codeforces 887A Div. 64 思维 模拟
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.
In the only line given a non-empty binary stringswith length up to100.
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
100010001
yes
100
no
In the first test case, you can get string1 000 000after removing two ones which is a representation of number64in the binary numerical system.
You can read more about binary numeral system representation here:https://en.wikipedia.org/wiki/Binary_system
思路:
先统计有多少个0,然后从前往后数,遇到第一个1时,判断后面剩余的0的个数是否大于等于6
代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() { 4 string s; 5 cin>>s; 6 int len=s.length(); 7 int cnt_zero=0; 8 int cnt_one=0; 9 for(int i=0;i<len;++i) { 10 if(s[i]=='0') cnt_zero++; 11 } 12 for(int i=0;i<len;++i) { 13 if(s[i]=='0') cnt_zero--; 14 if(s[i]=='1') break; 15 } 16 if(cnt_zero>=6) cout<<"yes"<<endl; 17 else cout<<"no"<<endl; 18 return 0; 19 }View Code 优质内容筛选与推荐>>
长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。
已发送
发送中
微信扫一扫
关注该公众号