download..仔细分析各种情况
#include<stdio.h> #include<string.h> /* N总的 num 为相等个数 t1为ch1中的1个数 t2为ch2中的1个数 可能性分析: 1.ch2全为1,steps 1 t2==N 2.ch1与ch2相等 steps 0 num==N 4.反转为的步数 steps 1 num=0 3.单选steps N-nums 4.全选后steps 1+N-t2 5.反选后steps 1+num 6.先全选后反选steps 2+t2 */ int max1(int x,int y) { return x<y?x:y; } int max2(int x,int y,int a,int b) { return max1(max1(x,y),max1(a,b)); } int main( ) { int N; char ch1[100],ch2[100]; while(scanf("%d",&N)!=EOF) { int i,t1=0,num=0,t2=0,s1=0,s2=0,s3=0,s4=0; scanf("%s%s",ch1,ch2); for(i=0;i<N;i++) { if(ch1[i]==ch2[i]) num++; if(ch1[i]=='1') t1++; if(ch2[i]=='1') t2++; } if(num==N) printf("0\n"); else if(num==0) printf("1\n"); else if(t2==N) printf("1\n"); else if(num==N-1) printf("1\n"); else { s1=N-num; s2=1+N-t2; s3=1+num; s4=2+t2; printf("%d\n",max2(s1,s2,s3,s4)); } } return 0; }
posted on 2011-05-02 11:59 more think, more gains 阅读(153) 评论(0) 编辑 收藏 举报