1610 - Party Games(细节题)

不知道为什么把这道题放在高效里,我这一点也不高效的方法居然也跑了0.016s

我们需要做的很简单,挨个字符的选择,然后先加上这个字符,和所有字符串比较一遍,根据大于它和小于它的字符串个数进行判断就好了 。  注意z这个字符 ,对于某些数据,会TLE的。。。

没什么意思,直接看代码吧:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 5;
int n,cnt[maxn];
char ans[35],s[maxn][35];
int main() {
    while(~scanf("%d",&n)&&n) {
        for(int i=1;i<=n;i++) {
            scanf("%s",s[i]);
            cnt[i] = strlen(s[i]);
        }
        int rear = 0;
        bool ok = false;
        while(!ok) {
            for(int j=0;j<26;j++) {
                int c = 0;
                char v = j + 'A';
                for(int i=1;i<=n;i++) {
                    ans[rear] = '\n';
                    if(rear+1 > cnt[i] && strcmp(ans,s[i]) >= 0) { c++; continue; }
                    else {
                        ans[rear] = v; ans[rear+1] = '\n';
                        if(strcmp(ans,s[i])>=0) c++;
                    }
                }
                if(v == 'Z'&&c<n/2) { ans[rear++] = v; break; }
                if(c == n/2) { ans[rear++] = v; ok = true; break; }
                if(c < n/2) continue;
                if(c > n/2) { ans[rear++] = v-1; break; }
            }
            if(ok) break;
        }
        for(int i=0;i<rear;i++) printf("%c",ans[i]);
        printf("\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值