0
Follow
0
View

# How to solve the problem of # Greed?

dayin781m 注册会员
2023-02-26 16:10
< div class = "md_content_show e397 data - v - 3967" = "" >

thank you

dd261591875 注册会员
2023-02-26 16:10
,a+ 1 ,b+ 1 ); int len= strlen (a+ 1 ); for ( int i= 1 ;i<=len;i++) { if (a[i]==b[i])a[i]=b[i]= 0 ; else a[i]=b[i]= 1 ; } if (len== 1 ) { if (a[ 1 ]== 0 ) printf ( "0\n" ); else printf ( "1\n" ); return 0 ; } if (len== 2 ) { if (a[ 1 ]!=a[ 2 ]) printf ( "impossible\n" ); else if (a[ 1 ]==a[ 2 ]) { if (a[ 1 ]== 0 ) printf ( "0\n" ); else printf ( "1\n" ); } return 0 ; } int n1= 1 ,n2= 0 ; a[ 1 ]^= 1 ;a[ 2 ]^= 1 ; for ( int i= 1 ;i<=len -1 ;i++) { if (a[i]== 1 ){a[i]^= 1 ;a[i+ 1 ]^= 1 ;a[i+ 2 ]^= 1 ;n1++;} if (b[i]== 1 ){b[i]^= 1 ;b[i+ 1 ]^= 1 ;b[i+ 2 ]^= 1 ;n2++;} } if (a[len]== 1 )n1= 999999999 ; if (b[len]== 1 )n2= 999999999 ; int ans= min (n1,n2); if (ans== 999999999 ) printf ( "impossible\n" ); else printf ( "%d\n" ,ans); return 0 ; } .
< !- - - - - >
daiyuchun 注册会员
2023-02-26 16:10
< div class = "md_content_show e397 data - v - 3967" = "" >

Publish Time
2023-02-26 16:10
Update Time
2023-02-26 16:10