摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1831先枚举公差,再枚举首项,这样可以直接输出在初始化中已经知道哪些数是双平方数,哪些不是 1 #include <iostream> 2 #include <algorithm> 3 #define MAX 250 4 using namespace std; 5 6 int n,m; 7 bool s[MAX*MAX*2+1]; 8 9 void ini()10 {11 int i,j;12 for(i=0;i<=m;i++)13 for(j=0;j<=m;j++) 阅读全文
posted @ 2013-01-24 17:45 tjsuhst 阅读(248) 评论(0) 推荐(0)
摘要: 最近发现简单题目所花费时间都很多,原因是cin, cout效率太低因为C++为了兼容C,所以读取时效率降低这个兼容可以设置,在关闭后,发现效率比scanf, printf都要高关闭C++标准stream(cin, cout, cerr)与C标准程序库文件(stdin, stdout,stderr)的同步,加上这样一行语句即可 ios::sync_with_stdio(false);效果:cin, cout,AC需要250msscanf, printf,AC需要78ms加上ios::sync_with_stdio(false); cin, cout,AC需要62ms 阅读全文
posted @ 2013-01-24 16:14 tjsuhst 阅读(670) 评论(0) 推荐(0)
摘要: 地址:http://codeforces.com/contest/262/problem/C快排 贪心打折方式肯定选小的,买东西时从价格高的买起用scanf, printf的效率比cin, cout高多了,一个78ms,一个250ms......差距 1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 using namespace std; 5 6 int m,n; 7 8 bool cmp(int a,int b) 9 {return a>b;}10 11 int m 阅读全文
posted @ 2013-01-24 15:49 tjsuhst 阅读(223) 评论(0) 推荐(0)
摘要: 地址:http://codeforces.com/contest/262/problem/B改正负k次,使得所有数字之和最大,数列是以非减形式给出全为负数时,此时若n<k则只能更改最后一个数,原来是最大负数,现在变成了最小正数并非全为负数,但n<k时,则要比较之前正负分界点两侧数字的大小,谁小就改谁当然n<k时,也可以当数列全为正后来一次排序 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int a[100000],n,k; 6 7 int main() 阅读全文
posted @ 2013-01-24 13:18 tjsuhst 阅读(189) 评论(0) 推荐(0)
摘要: 地址:http://codeforces.com/contest/265/problem/C给一段长度为n的序列,新建一个数组来记录石头位置信息,遇到r从头往尾记录,遇到l从尾往头记录一开始都开的是大小为106的数组,用了1406ms才过,觉得太慢,用了动态分配,时间上并未节省,只不过减少了内存开销 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 string in; 6 7 int main() 8 { 9 int i,j,k,n;10 getline(cin,in);11 阅读全文
posted @ 2013-01-24 12:16 tjsuhst 阅读(192) 评论(0) 推荐(0)