Codeforces Round #235 (Div. 2)
来源:互联网 发布:淘宝小样几乎都是假的 编辑:程序博客网 时间:2024/05/21 18:37
昨晚的比赛真是揪心,B题读了二十多分钟才明白题意,还发现如此之水。咔咔咔刷了三题,发现这三题都有四位数以上的人过了-_-|||。心想那就一千多名吧,结果第二天早上起来发现C题被hack掉了。。。
说多了都是泪呀。。。
A. Vanya and Cards
题意:有n张标有整数的牌,求至少需要几张数字范围在[-x,x]以内的牌,使得连同那n张牌的数字总和为0。
分析:水题,求出n张牌与0差多少就可以了
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int abs(int i) { if(i<0) return -i; return i;}int n,x;int main() { while(~scanf("%d%d",&n,&x)) { int sum = 0; int a; for(int i=0; i<n; i++) { scanf("%d",&a); sum+=a; } int need = abs(0 - sum); //cout<<"******"<<x<<endl; int ans; ans=need/x; if(need%x!=0) { ans++; } printf("%d\n",ans); } return 0;}
B. Sereja and Contests
题意:
有若干场比赛,分为div1和div2,一个小时一场比赛无间断,div1举办的前提是跟在div2后面。Sereja只能参加div2,现在他正在参加第n场比赛,再给出k场他参加过的比赛,问他最少和最多缺少过多少场比赛。
分析:
比赛的范围是在[1,n],把Sereja参加过的比赛都标记下来,剩下的就是他没参加过div2的或者是他不能参加的div1,如果全部是div2,那么就是他最多缺场数,如果每一场div2后面都能够跟着一场div1,那么这就是他最少缺场数。
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int x,k;bool cnt[4567];int main(){ while(~scanf("%d%d",&x,&k)){ memset(cnt,false,sizeof(cnt)); //cout<<"********"<<endl; int flag,num1,num2; for(int i=0;i<k;i++){ scanf("%d",&flag); if(flag - 2 == 0){ scanf("%d",&num2); cnt[num2] = true; } else{ scanf("%d%d",&num2,&num1); cnt[num1] = true; cnt[num2] = true; } } cnt[x] = true; int maxn=0,minn=0; bool TS = false; for(int i=1;i<=x;i++){ if(!cnt[i]){ maxn++; if(!cnt[i-1] && TS){ TS = false; } else{ minn++; TS = true; } } } //cout<<"********"<<left<<endl; printf("%d %d\n",minn,maxn); } return 0;}
C. Team
题意:
n个0,m个1,对这些数排列,使得:
(1)两端不能有一对0出现
(2)不能出现3个连续的1
输出任意一个满足的排列,不存在输出-1。
分析:
如果n<m/2-1(或者m/2,看m的奇偶性) 或者 n>m+1,输出-1,其他情况操作一下即可
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int n,m;int main(){ while(~scanf("%d%d",&n,&m)){ if(n==2 && m==1){ printf("010\n"); continue; } if(n==1 && m==2){ printf("101\n"); continue; } if(n==1 && m==1){ printf("01\n"); continue; } int tmp; if(m%2==0) tmp = m/2; else tmp = m/2+1; tmp--; if(n < tmp || (n>2 && m<2) || n>m+1){ printf("-1\n"); continue; } if(n >= tmp && (n<=m)){ //cout<<"********"<<endl; while(m>n && n>0){ printf("110"); m-=2; n--; } if(n!=0){ while(n>0){ printf("10"); m--; n--; } } else{ while(m>0){ printf("1"); m--; } } printf("\n"); continue; } printf("01"); n-=2; m-=2; while(m>0){ printf("01"); n--; m--; } while(n>0){ printf("0"); n--; } printf("10\n"); } return 0;}
0 0
- Codeforces Round #235 (Div. 2)
- Codeforces Round #235 (Div. 2)
- Codeforces Round #235 (Div. 2)
- [Codeforces] Round #235 (Div. 2)
- Codeforces Round #235 (Div. 2)
- Codeforces Round #235 (Div. 2)
- Codeforces Round #235 (Div. 2)
- Codeforces Round #235 (Div. 2) A~D
- Codeforces Round #235 (Div. 2) A
- Codeforces Round #235 (Div. 2) C
- Codeforces Round #235 (Div. 2)__C. Team
- Codeforces Round #235 (Div. 2)C. Team
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- org.hibernate.exception.GenericJDBCException: 只进结果集不支持请求的操作。 异常处理方法
- sicily 1934. 移动小球
- 文件上传之 commons-fileupload(二)
- javascript——js string 转 int
- JAVA工具类 UUID
- Codeforces Round #235 (Div. 2)
- Android 使用Parcelable序列化对象
- JSP中EL表达式、JSTL、java脚本、js嵌套问题
- 猎头如何迅速的了解一个行业 (借鉴猎头)
- Servlet中转发和重定向的路径问题以及表单提交路径问题
- 数位DP小记 + HDU 2089 不要62
- 解决ORA-12519: TNS:no appropriate service handler found问题
- MySql导入导出数据库(含远程导入导出)
- 存储过程同函数的区别