标签:name inf mis include tput put 长度 存在 change
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3669 Accepted Submission(s): 1371
1 #include "cstdio" 2 #include "iostream" 3 #include "algorithm" 4 #include "string" 5 #include "cstring" 6 #include "queue" 7 #include "cmath" 8 #include "vector" 9 #include "map" 10 #include "stdlib.h" 11 #include "set" 12 #define mj 13 #define db double 14 #define ll long long 15 using namespace std; 16 const int N=1e6+5; 17 const int mod=1e9+7; 18 const ll inf=1e16+10; 19 char s[N]; 20 int a[N]; 21 int dfs(int i,int n,int cnt){ 22 if(i==n){//判断最后一张牌的状态 23 if(a[n-1]) return 1e8; 24 else return cnt; 25 } 26 if(a[i-1]) a[i-1]=!a[i-1],a[i]=!a[i],a[i+1]=!a[i+1],cnt++; 27 return dfs(i+1,n,cnt); 28 } 29 int main() 30 { 31 int n; 32 while(scanf("%s",s)==1){ 33 int ans; 34 n=strlen(s); 35 for(int i=0;i<n;i++) 36 a[i]=s[i]-‘0‘; 37 a[0]=!a[0],a[1]=!a[1]; 38 ans=dfs(1,n,1); 39 for(int i=0;i<n;i++) 40 a[i]=s[i]-‘0‘; 41 ans=min(ans,dfs(1,n,0));//取最小值 42 if(ans==1e8) printf("NO\n"); 43 else printf("%d\n",ans); 44 45 } 46 return 0; 47 }
标签:name inf mis include tput put 长度 存在 change
原文地址:http://www.cnblogs.com/mj-liylho/p/7148068.html