zeros and ones (找规律)
来源:互联网 发布:房地产 知乎 编辑:程序博客网 时间:2024/06/06 05:41
1518: Zeros and Ones
时间限制: 1 Sec 内存限制: 128 MB
提交: 133 解决: 51
[提交][状态][讨论版]
题目描述Consider strings of characters made up by concatenating any number of the strings 0, 01 or 11.
For example 00011111 is one such string, as is 001011, but 1011 is not. Your job is simply to determine if a given string can be constructed in this manner.输入
There will be multiple problem sets. Input for each problem will be on one line. Each line (except
the last) will be of the form
n s
where n is a non-negative integer no larger than 100 and s is a string of 0’s and 1’s of length n.
A value of n = 0 indicates end of input.
输出Each problem should generate one line of code, either,
String m can be generated.
or
String m can not be generated.
accordingly, where m is the number of the problem (stating at 1).
样例输入8 00011111
6 001011
4 1011
0样例输出
String 1 can be generated.
String 2 can be generated.
String 3 can not be generated.
题目链接
这题就是找规律,假如第一个是0,那么后面有多少个1都没关系。把0 是gril 1是boy,偶数个1,gay 的1 cp组合后刚刚好,那么girl就单身了,奇数个1,即使cp组合还是会留下一个1,这样剩下一个1就和0搭配。
关键就是1开头,如果全是1,那么奇数个1就组不了gay 的1cp。就算不全是1,那么第一个0出现时,前面的1必须能够cp 组合才行。
#include<stdio.h>int main(){ int n; char a[102],j=1; while(scanf("%d",&n)&&n) { int i; getchar(); for(i=0;i<n;i++) scanf("%c",&a[i]); for(i=0;a[i]=='1'&&i<n;i++) ; //a[0]='0',就说明girl(s)可以被灵活的分配,可以单着,也可为祖国婚姻事业做贡献。如果a[0]='1',在下个0到来之前如果是奇数就gg。 printf("String %d can %s generated.\n",j++,i%2==0?"be":"not be"); }}
- zeros and ones (找规律)
- Ones and Zeros
- Zeros and Ones
- UVa10324 - Zeros and Ones
- 10324 - Zeros and Ones
- Zeros and Ones
- the Zeros and Ones
- [leetcode]ones and zeros
- Zeros and Ones UVA
- UVa:10324 - Zeros and Ones
- UVa -- 10324 Zeros and Ones
- UVa 10324 - Zeros and Ones
- UVA - 10324 Zeros and Ones
- TOJ 3519.Ones and Zeros
- [UVA12063] Zeros and Ones && 数位DP
- A. Case of the Zeros and Ones
- A. Case of the Zeros and Ones
- Case of the Zeros and Ones
- vs2012 error LNK2038 RuntimeLibrary 不匹配的解决
- HDU 1546 Idiomatic Phrases Game
- HttpClient学习整理
- ToolBar的使用
- Android实现简单的纸飞机操作(类似于漂流瓶)
- zeros and ones (找规律)
- docker 部署 shipyard
- APK瘦身
- C++语言概述
- AngularJs2 http 与SpringMVC后台交互传参问题
- Unable to execute dex: Multiple dex files define Lcom/loopj/android/http/AsyncHttpClient$1
- 方法
- HDU1018 Big Number
- Java中throw之后还会继续运行吗?