南邮 OJ 1965 GAME
来源:互联网 发布:linux select串口 编辑:程序博客网 时间:2024/06/04 23:26
GAME
时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte
总提交 : 54 测试通过 : 18
总提交 : 54 测试通过 : 18
比赛描述
There is a string which consists 0s and 1s only.
Each time you can change one digit, with 0 changed to 1, or 1 changed to 0.
But when you change the digit, the digits on its left and right is changing in the same way.
Please tell me the minimum moves to change the string to 00…000.
If it is impossible please output “NO” in a single line.
Each time you can change one digit, with 0 changed to 1, or 1 changed to 0.
But when you change the digit, the digits on its left and right is changing in the same way.
Please tell me the minimum moves to change the string to 00…000.
If it is impossible please output “NO” in a single line.
输入
In each line there is a string. The length of the string is shorter than 20.
输出
For each string you have to output the minimum number or “NO” in a single line.
样例输入
01
011
101
样例输出
NO
1
2
题目来源
2B
#include<iostream>using namespace std;#define MAX_LEN 21char a[MAX_LEN],b[MAX_LEN];void reverse(char *c, int i){for(int j=max(0,i-1);j<=i+1;j++){if(c[j]=='0'){c[j] = '1';}else if(c[j]=='1'){c[j] = '0';}}}int main(){int i,len,count,r;while(scanf("%s",a)==1){len = (int)strlen(a);strcpy(b,a);count = 0;for(i=0; i+1<len; i++){if(a[i]=='1'){reverse(a,i+1);count++;}}if(a[len-1]=='1'){r = -1;}else{r = count;}count = 1;reverse(b,0);for(i=0; i+1<len; i++){if(b[i]=='1'){reverse(b,i+1);count++;}}if(b[len-1]=='0'){if(r==-1 || r>count){r = count;}}if(r==-1){printf("NO\n");}else{printf("%d\n",r);}}}
0 0
- 南邮 OJ 1965 GAME
- 南邮 OJ 1105 Game
- LeetCode OJ:Jump Game
- LeetCode OJ - Jump Game
- Leetcode OJ Dungeon Game
- Leecode OJ Jump Game
- UVa OJ Kindergarten Counting Game
- uestc oj 1488 Flip Game
- LeetCode OJ:Jump Game II
- LeetCode OJ - Jump Game II
- hdu-oj 1846 Brave Game
- LeetCode OJ Jump Game II
- <LeetCode OJ> 292. Nim Game
- [leedcode oj 292]Nim Game
- <LeetCode OJ> 55. Jump Game
- LIGHT OJ 1199 - Partitioning Game
- LeetCode OJ-292. Nim Game
- 关于博弈(OJ kiki'game)
- AFNetworking2.5版本的使用
- 二分图--最大匹配
- solr 5.2.1
- Tomcat启动内存设置
- 怎样从一个DLL中导出一个C++类
- 南邮 OJ 1965 GAME
- 7. 事务
- ssh,nfs服务配置
- 文件操作类
- Python多线程,生产者-消费者-终结者
- html手机自适应代码
- 修改Tomcat Connector运行模式,优化Tomcat运行性能
- 程序员如何持续提升自己的开发技能
- GDB调试