随笔分类 - Codeforces
摘要:地址:http://codeforces.com/contest/270/problem/D这题看过别人代码,理解了好久本来觉得这题和USACO里的三值的排序是一样的,但是USACO里通不过......看来还得想 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,m,s[5001],p[5001]; 6 double x; 7 8 int main() 9 {10 ios::sync_with_stdio(false);11 int j;12 cin>>
阅读全文
摘要:地址:http://codeforces.com/contest/270/problem/C边读边算,算出当前所需最小箱子,每次结果进行对比,找最大 1 #include <iostream> 2 using namespace std; 3 4 int n,k,a; 5 6 int main() 7 { 8 ios::sync_with_stdio(false); 9 cin>>n;10 int ans=0;11 for(int i=0;i<n;i++)12 {13 cin>>k>>a;14 if(1==a) k++...
阅读全文
摘要:地址:http://codeforces.com/contest/270/problem/B更新的数字会上浮,从后往前找降序子串,这就是没有更新的,从而得到更新的数量 1 #include <iostream> 2 using namespace std; 3 4 int n,a[100000]; 5 6 int main() 7 { 8 ios::sync_with_stdio(false); 9 int con=1;10 cin>>n;11 for(int i=0;i<n;i++)12 {13 cin>>a[i];14 }...
阅读全文
摘要:地址:http://codeforces.com/contest/270/problem/A用多边形外角来做,外角和为360度,然后比对边数 1 #include <iostream> 2 using namespace std; 3 4 int t,a; 5 6 int main() 7 { 8 ios::sync_with_stdio(false); 9 cin>>t;10 while(t--)11 {12 cin>>a;13 int n;14 n=360/(180-a);15 int su...
阅读全文
摘要:地址:http://codeforces.com/contest/268/problem/C给定一个平面0 ≤ x ≤ n;0 ≤ y ≤ m;x + y > 0,在其中寻找一个最大的坐标均为整数的点集,且每两点间的距离不为整数找无理数也可以,三角形可以变成一个线段,只要两段距离为无理数,那么第三个距离也是无理数所以寻找这样的平面内最大的正方形,选择其副对角线上的点输出 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,m; 6 7 int main() 8
阅读全文
摘要:地址:http://codeforces.com/contest/268/problem/B找规律,有公式,累加即可 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,ans; 6 7 int main() 8 { 9 ios::sync_with_stdio(false);10 int i,j;11 cin>>n;12 for(i=n-1,j=1;i>=0 && j<=n;i--,j++)13 {14 if(i==0) an
阅读全文
摘要:地址:http://codeforces.com/contest/268/problem/A枚举的同时计数... 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,h[30],a[30]; 6 7 int main() 8 { 9 ios::sync_with_stdio(false);10 int con=0;11 cin>>n;12 for(int i=0;i<n;i++)13 {14 cin>>h[i]>>a[i];1
阅读全文
摘要:地址: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
阅读全文
摘要:地址: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()
阅读全文
摘要:地址: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
阅读全文
摘要:地址: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
阅读全文
摘要:地址: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
阅读全文
摘要:地址: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'
阅读全文
摘要:地址:http://codeforces.com/contest/266/problem/A可以看作是记录连续重复序列的长度和 1 #include<stdio.h> 2 3 int n; 4 char in[55]; 5 6 int main() 7 { 8 int i,count=0; 9 scanf("%d",&n);10 scanf("%s",in);11 for(i=0;i<n-1;i++)12 {13 if(in[i]==in[i+1])14 {15 count++;16 ...
阅读全文
摘要:地址:http://codeforces.com/contest/265/problem/B爬树吃坚果,很明显树顶走是最短路 1 #include<stdio.h> 2 3 int n,h[2]; 4 5 int main() 6 { 7 int i,ans=0; 8 scanf("%d",&n); 9 for(i=0;i<n;i++)10 {11 scanf("%d",&h[1]);12 if(0==i)13 {14 ans=h[1]+1;15 h[0]=h[1...
阅读全文
摘要:地址:http://codeforces.com/contest/233/problem/A这题好像做过,接下来几天要做点有难度的题 1 #include<stdio.h> 2 3 int n; 4 5 int main() 6 { 7 int i; 8 scanf("%d",&n); 9 if(n%2==0)10 {11 for(i=1;i<=n;i=i+2)12 printf("%d %d ",i+1,i);13 }14 else printf("-1\n");15 return 0;16 ...
阅读全文
摘要:地址:http://codeforces.com/contest/234/problem/A排座位,左右撇子都有,要求每两个人坐一起手不打架 1 #include<stdio.h> 2 3 int n; 4 5 int main() 6 { 7 int l,r; 8 char in[101]; 9 freopen("input.txt","r",stdin);10 freopen("output.txt","w",stdout);11 scanf("%d",&n);12 sc
阅读全文
摘要:地址:http://codeforces.com/contest/239/problem/A按题目说的求就是了 1 #include<stdio.h> 2 3 int y,k,n; 4 5 int main() 6 { 7 int i; 8 scanf("%d %d %d",&y,&k,&n); 9 i=(y/k+1)*k-y;10 if(i>n-y) printf("-1\n");11 else12 {13 while(i<=n-y)14 {15 printf("%d ",i);16
阅读全文
摘要:地址:http://codeforces.com/contest/265/problem/A昨晚没时间参赛 1 #include<stdio.h> 2 #include<string.h> 3 4 char a[50],b[50]; 5 6 int main() 7 { 8 int i=0,j=0,len; 9 scanf("%s",a);10 scanf("%s",b);11 len=(int)strlen(b);12 for(j=0;j<len;j++)13 {14 if(b[j]==a[i]) i++;15 }1...
阅读全文
摘要:地址:http://codeforces.com/contest/237/problem/A想服务所有顾客,要多少cash,同时来的肯定不能在同一台cash上这题我错了好多次才AC...... 1 #include<stdio.h> 2 3 int a,b,c,d,n; 4 5 int main() 6 { 7 int i,count=1,ans=0; 8 scanf("%d",&n); 9 for(i=0;i<n;i++)10 {11 scanf("%d %d",&c,&d);12 if(i==0)13 {1.
阅读全文