zoj3829 Known Notation --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest

根据规则,可以发现,一*之前必须有至少2数字。一(11*)这反过来可以被视为一数字。

因此,总位数必须大于*号码,或者你会加入数字。

添加数字后,,为了确保该解决方案将能够获得通过交流。那么肯定是*放回去,图提出。交易所至今资格。



#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[1010];
int len,ans,opp[1010],num[1010],op,cnt;
bool check(int b)
{
    int a=0;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='*') a++;
        else b++;
        if(a>=b) return 0;
    }
    return 1;
}
int main()
{
    int T,i,j,b;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",s);
        len=strlen(s);
        cnt=op=ans=0;
        for(i=0;i<len;i++)
        {
            if(s[i]=='*') opp[op++]=i;
            else num[cnt++]=i;
        }
        if(op==0)
        {
            puts("0");
            continue;
        }
        for(i=0,j=cnt-1;i<j;i++,j--) swap(num[i],num[j]);

        if(op>=cnt) ans+=(op-cnt+1);
        int fir=0,last=0;
        b=ans;
        while(!check(b))
        {
            ans++;
            swap(s[opp[fir++]],s[num[last++]]);
        }
        printf("%d
",ans);
    }
    return 0;
}


版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/blfshiye/p/4833340.html