CodeForces 405C
来源:互联网 发布:seo实战密码 epub 编辑:程序博客网 时间:2024/04/30 14:00
链接:点击打开链接
题意:给n张带数字0的牌和m张带数字1的牌,输出组成后的序列(不能含有连续的三个1并且不能含有连续的两个0)
代码:
#include <cstdio>#include <stdlib.h>#include <algorithm>using namespace std;int main(){ int m,n,i; while(scanf("%d%d",&n,&m)!=EOF){ if(m<n-1||m>2*n+2){ puts("-1"); continue; } //根据01010....10和110110...11011推出输出-1的情况 if(m==n-1){ //除去m=n-1其余情况m都比n多 printf("0") ; for(i=1;i<=m;i++) printf("10"); printf("\n"); continue; } while(m>n){ //因为m==n或者m==n+2或者m=n+1时可以和容易输出 printf("110"); //因此尽可能输出110,然后再在适当条件跳出 m-=2,n--; if(m==n+2||m==n+1) break; } if(m==0&&n==0){ printf("\n"); continue; } if(m==n+2){ for(i=1;i<=n;i++) printf("10"); printf("11\n"); continue; } if(m==n+1){ for(i=1;i<=n;i++) printf("10"); printf("1\n"); continue; } if(m==n){ for(i=1;i<=n;i++) printf("10"); continue; } } return 0;}
0 0
- Codeforces 405C
- CodeForces 405C
- CodeForces - 405C
- CodeForces 405C Unusual Product
- CodeForces 405C Unusual Product
- Codeforces 405C Unusual Product
- Codeforces 405C Unusual Product
- codeforces 405C Unusual Product
- CodeForces 405C Unusual Product【思维】
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- 乐观锁与悲观锁
- Java TreeMap 源码解析
- LIRE原理与源码分析(二)——相关接口
- Python中的装饰器decorator
- VPN穿透内网实现校园网24小时不断网
- CodeForces 405C
- Java回调函数的理解
- 安装Ubuntu 15 Kylin 网络线口不亮 连不上网 网络驱动更换[终极解决办法]
- SDUT-二叉树先序 中序建树求树高
- 二胎
- Cocos2d-x 中加载骨骼动画资源
- 多线程 —— GCD
- Java自动装箱和自动拆箱源码分析
- hdu1010 Tempter of the Bone