linest
linest · 共 118 篇文章
console 输入输出
读EOF结尾 scanf返回读出变量数 如果没读出返回-1 EOF就是常量-1 while(scanf("%d %d",&a,&b)!=EOF) { } while(cin>>a>>b) { } 读字符串整行 scanf以空格分隔 gets以回车分隔 char buf[20]; gets(buf); string buf; getline(cin,buf); char buf[20]; //参数1 数组 参数2 读取个数 参数3 结束符默认'\n' cin.getline(buf,255,'\n');
2012-04-10 17:06 · c/c++ · 评论(0)
-1.#IND00
使用pow函数做开方操作 pow(-10,1/3.0) 结果是奇怪的-1.#IND00 查了一下原来pow的第一个参数要是正数, so -pow(10,1/3.0) 类似的错误是sqrt(-1) 负数开平方也会同样报错
2012-04-09 16:40 · c/c++ · 评论(0)
malloc 和 calloc
两者都是从堆上申请空间 malloc只有一个参数,就是分配大小 calloc有两个参数,分别是元素数目和每个元素大小 calloc返回一个元素数组而malloc只返回一个空间整体 malloc分配的空间不会初始化 calloc分配时会初始化
2012-04-03 11:11 · c/c++ · 评论(0)
hadoop 实践
http://blog.csdn.net/dajuezhao/article/details/6591034 写的很好 保存留用~ 一、背景 Hadoop的集群使用也有些时候了,不过都是小集群的使用(数量小于30台)。在这个过程中不断的进行着配置调优的操作。最早的时候,在网上也没有找到一些合适的配置调优方法,于是,我在这里列举一些基本的调优配置,以供参考。最后,还有一个我自己的测试环境的配置说明,也可以参看一下。 二、环境和配置 版本和环境 Ø Hadoop版本:apache发布的0.21 Ø 操作系统:Linux Ø JDK:1.6 Ø 网络环境为千兆网络 hdfs-site.xml配置文…
2012-03-22 10:20 · hadoop · 评论(0)
python 细碎内容
http://www.coder4.com/archives/2239 #设a为字符串 import time a = "2011-09-28 10:00:00" #中间过程,一般都需要将字符串转化为时间数组 time.strptime(a,'%Y-%m-%d %H:%M:%S') >>time.struct_time(tm_year=2011, tm_mon=9, tm_mday=27, tm_hour=10, tm_min=50, tm_sec=0, tm_wday=1, tm_yday=270, tm_isdst=-1) #将"2011-09-28 10:00:00"转化为时间戳 ti…
2012-03-11 10:27 · python · 评论(0)
pat-1022 Digital Library
可能的查询 ID值进行map映射 以下代码有问题,原因是ID是整形保存,会忽略前面的0 #include<iostream> using namespace std; #include<string> #include<vector> #include<map> #include<set> #include<algorithm> int main() { int N; map<string,set<int>> m; int ID; int index; string title; string author; string keyword; string publisher; string …
2012-02-27 14:26 · pat · 评论(2)
pat-1016 Phone Bills
Sample Input:10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10 10 CYLL 01:01:06:01 on-line CYLL 01:28:16:05 off-line CYJJ 01:01:07:00 off-line CYLL 01:01:08:03 off-line CYJJ 01:01:05:59 on-line aaa 01:01:01:03 on-line aaa 01:02:00:01 on-line CYLL 01:28:15:41 on-line aaa 01:05:…
2012-02-27 00:01 · pat · 评论(0)
pat-1018 Public Bike Management 有问题
最后一个case还过不了 == 为什么呢 思路dfs遍历到目标的所有路径 找最短,运送最少,带回最少的路径 #include <iostream> #include <vector> #include<memory.h> using namespace std; #define MAXV 501 #define INFINITE 1000000000 int mindis = INFINITE; int mincarry = INFINITE; int minback; vector<int> minpath; int status[maxv]; int use[maxv]; int map…
2012-02-26 19:55 · pat · 评论(0)
pat-1017* Queueing at Bank
银行8点至17点开 有固定窗口数 来早了要等,没窗口要等,17点后才来就无视 求平均等待时间, 被无视的不统计 注意不是17点一定关门,只要是17点前来的都要服务,即使可能超时 下面代码完全模拟秒数,先排序顾客,滤掉17点后来的 对于每一秒,检查窗口的情况 总体思路是以时间为中心 #include<iostream> using namespace std; #include<string> #include<vector> #include<stdio.h> #include<algorithm> #include<queue> struct Customer { int arrive; …
2012-02-25 12:32 · pat · 评论(0)
pat-1021* Deepest Root
判断图是否都连接构成树,求使树高最大的根 实际上求图上两点间最大距离 先用并查集判断共有几个部分 bfs求距离 先任取一点开始bfs,得到最远的叶节点 以此叶节点再bfs可得 #include<iostream> using namespace std; #include<string> #include<vector> #include<queue> #include<set> #include<memory.h> #include<algorithm> #define MAXV 10001 int dist[maxv]; // store distance int points[maxv…
2012-02-25 00:36 · pat · 评论(0)
pat-1020* Tree Traversals
给后序和中序遍历 求层序遍历 Sample Input:7 2 3 1 5 7 6 4 1 2 3 4 5 6 7 Sample Output:4 1 6 3 5 7 2 注意如果是按char型处理,还要考虑多字符情况 如12 在输入上要加以处理,用int比较简单 #include "stdio.h" #include "stdlib.h" typedef struct bt_node // 定义二叉树结点。 { char data ; struct bt_node * left ; struct bt_node * right ; } bt_node ; //搜索根在中序数组中的下标,若两…
2012-02-23 15:20 · pat · 评论(0)
pat-1019 General Palindromic Number
判断数字在给定进制下是否回文 并打出进制转换后系数 思路,将所有系数存起来处理 #include<iostream> using namespace std; #include<vector> #include<algorithm> int main() { vector<int> v; vector<int> rv; int num; int base; cin>>num; cin>>base; while(num) { v.push_back(num%base); num/=base; } rv = v; reverse(rv.begin(),rv.end()); if(rv==v) c…
2012-02-23 00:26 · pat · 评论(0)
pat-1024 Palindromic Number
如果不是回文则进行逆序相加操作,打印出最后回文和操作次数 题目中说数字可达到10的10次方 迭代可100次 则每次相加次数可能因进位多一位,longlong型只能19位可能不够 实现重点,字符串相加 注意求进位时也要带上carry 以下代码数值型会溢出 #include<iostream> using namespace std; long long reverse(long long in) { long long tmp = in; long long re = 0; while(tmp) { re *= 10; re += tmp % 10; tmp /= 10; } return r…
2012-02-20 00:56 · pat · 评论(0)
pat-1025 PAT Ranking
不同地点一起排序 先组内排序,再全局排序 将小组添加进全局 vector拼接 globallist.insert(globallist.end(),locallist.begin(),locallist.end()); #include<iostream> using namespace std; #include<vector> #include<string> #include<algorithm> struct Score { string id; int score; int local; int global; int location; }; bool sortByScore(S…
2012-02-19 15:45 · pat · 评论(0)
pat-1023 Have Fun with Numbers
判断一个数乘2后是否是原数的一个排列 思路: int最大值 2147483647 10位 longlong 最大值 9223372036854775807 19位 不满足题目20位 故不能数值型 只能字符串处理 考虑乘积后进位问题 排列的判断用二进制移位求和即可,和值相等即为排列。 #include<iostream> using namespace std; #include<string> int add(int n) { return 1<<n; } void compare(string str) { int len = str.length(); int carry = 0; in…
2012-02-19 00:26 · pat · 评论(0)