2022.3.28# Codeforces Round #779 (Div. 2) A.Marin and Photoshoot
作者:互联网
2022-03-28
两个0之间至少有2个1,所以判断两个0之间的间隔,也就是1的数量,如果少于2那就sum++;
1 #include<iostream> 2 #include<vector> 3 #include<string> 4 #include<unordered_map> 5 #include<algorithm> 6 #include<cmath> 7 #define maxn 100010 8 #define ll long long 9 #define lld double 10 using namespace std; 11 12 inline int read() 13 { 14 int x = 0;char c = getchar(); 15 while (c < '0' || c>'9') c = getchar(); 16 while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); 17 return x; 18 } 19 void solve() 20 { 21 int n; 22 cin>>n; 23 char s[1000]; 24 scanf("%s",s); 25 vector<int>vec; 26 for(int i=0;i<n;i++) 27 if(s[i]=='0') 28 vec.push_back(i); 29 30 if(vec.empty()) 31 { 32 cout<<0<<endl; 33 return; 34 } 35 int ans=0; 36 for(int i=1;i<vec.size();i++) 37 { 38 ans+=max(0,2-(vec[i]-vec[i-1]-1)); 39 } 40 41 cout<<ans<<endl; 42 } 43 int main(void) 44 { 45 ios_base::sync_with_stdio(0); 46 cin.tie(0); 47 int t; 48 cin>>t; 49 while(t--) 50 { 51 solve(); 52 } 53 return 0; 54 }
水题都不会做,懈怠了。
标签:int,28,779,Codeforces,char,while,include,define 来源: https://www.cnblogs.com/Tiachi/p/16067690.html