标签:
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <cstring> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <map> #define PI 3.1415926 #define ms(a) memset(a,0,sizeof(a)) #define msp memset(mp,0,sizeof(mp)) #define msv memset(vis,0,sizeof(vis)) using namespace std; //#define LOCAL int a[120]; int ans; int dfs(int i,int len,int cnt) { if(i==len) { if(a[len-1])return 1e9; else return cnt; } if(a[i-1])a[i-1]=0,a[i]=!a[i],a[i+1]=!a[i+1],cnt++; return dfs(i+1,len,cnt); } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL ios::sync_with_stdio(false); char t[120]; while(cin>>t) { int len=strlen(t); for(int i=0;i<len; i++)a[i]=t[i]-‘0‘; a[0]=!a[0],a[1]=!a[1]; int ans=1e9; ans=min(dfs(1,len,1),ans); for(int i=0,len=strlen(t);i<len; i++)a[i]=t[i]-‘0‘; ans=min(dfs(1,len,0),ans); if(ans==1e9)printf("NO\n"); else printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/gpsx/p/5180339.html