poj 3276 Face The Right Way

poj 3276 Face The Right Way,第1张

poj 3276 Face The Right Way
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int cow[5005],temp[5005];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        char ch,lc='F';        for(int i=1;i<=n;i++)        { scanf(" %c",&ch); if(lc==ch)     cow[i]=0; else     cow[i]=1; lc=ch;        }        int ansk,ansm=1<<30;        for(int k=1;k<=n;k++)        { int tp=0; memcpy(temp,cow,sizeof(cow)); for(int i=1;i<=n-k+1;i++)     if(temp[i])         tp++,temp[i+k]^=1; for(int i=n-k+2;i<=n;i++) {     if(temp[i])     {         tp=1<<30;         break;     } } if(ansm>tp) {     ansm=tp;     ansk=k; }        }        printf("%d %dn",ansk,ansm);    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4911346.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存