摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1836摆棋子,但是其横竖斜向均不可另有棋子,输出前三种解(按字典序输出),并输出总解数 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #define MAX 13 5 using namespace std; 6 7 int a[MAX]; 8 int n,con; 9 10 void print()11 {12 for(int i=0;i<n;i++)13 {14 cout 阅读全文
posted @ 2013-01-25 13:07 tjsuhst 阅读(368) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(237) 评论(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 阅读(632) 评论(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 阅读(217) 评论(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 阅读(180) 评论(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 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 地址:http://codeforces.com/contest/263/problem/B给出n个正方形的顶点(与(0,0)在同一对角线上),要求找到一个点包含在k个正方形内n<k则无法找到n>=k时,读入数据后排序输出从右数第k个顶点的坐标即可 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,k,a[55]; 6 7 bool cmp(int a,int b) 8 {return a<b;} 9 10 int main()11 {12 int 阅读全文
posted @ 2013-01-23 18:15 tjsuhst 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1826快排(用了两次,一次升序,一次降序,其实都用降序就行了)将牛棚间间隔最大的那几个减去即可,注意所需木板的最小总长应该是有牛的牛棚的个数,就这一点让我错了好多次 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int m,s,c,st[200]; 6 7 bool cmp1(int a,int b) 8 { 9 return a>b;10 }11 12 bool cmp2(in 阅读全文
posted @ 2013-01-23 15:49 tjsuhst 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 地址:http://codeforces.com/contest/266/problem/C这题比赛时没做出来这还是看了dys的题解才写出来...... 1 #include<stdio.h> 2 3 int n,m[1000][2],result[10000][3]; 4 5 int main() 6 { 7 int i,j,count=0; 8 scanf("%d",&n); 9 for(i=0;i<n-1;i++)10 {11 scanf("%d %d",&m[i][0],&m[i][1]);12 }13 阅读全文
posted @ 2013-01-23 15:24 tjsuhst 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 地址:http://codeforces.com/contest/266/problem/B时间一秒一秒的减,没有人换位或是时间到就停止#include<stdio.h>int n,t;char in[55];int main(){ int i,flag=0; scanf("%d %d",&n,&t); scanf("%s",in); while(t>0) { flag=0; for(i=0;i<n-1;) { if(in[i]=='B' && in[i+1]=='G' 阅读全文
posted @ 2013-01-23 15:22 tjsuhst 阅读(162) 评论(0) 推荐(0) 编辑