codeforces 278B New Problem

B. New Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.

You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.

A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is string slsl + 1... sr.

String x = x1x2... xp is lexicographically smaller than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there exists such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The string characters are compared by their ASCII codes.

Input

The first line contains integer n (1 ≤ n ≤ 30) — the number of titles you've got to consider. Then follow n problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive.

Output

Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title.

Sample test(s)
Input
5
threehorses
goodsubstrings
secret
primematrix
beautifulyear
Output
j
Input
4
aa
bdefghijklmn
opqrstuvwxyz
c
Output
ab
Note

In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.

In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title.


题目叫你找一个最小的新标题,要求是标题不能与原有标题重复。刚开始一直搞错了,以为只是找两个长度的字符串。后来发现是整个字符串里面去寻找。这个时候,就可以用一个strstr函数来达到目标。strstr函数是用来搜索字符串的,即Strstr(str1,str2),在1中寻找2是否出现,如果不出现就返回NULL了,否则就返回字符串的其余部分。

这样一来就简单了。

#include<stdio.h>
#include<string.h>
int main()
{
    char zimu[]={
        'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s',
        't','u','v','w','x','y','z'
    };
    int n,i,j,k,l[40],hash[200],f,mark;
    char str[40][40],yuan[2];
    while(scanf("%d",&n)!=EOF)
    {    
        memset(hash,0,sizeof(hash));
        f=0;mark=0;
        for(i=1;i<=n;i++)
        {
            scanf("%s",&str[i]);
            l[i]=strlen(str[i]);
            for(j=0;j<l[i];j++)
            hash[str[i][j]-'a']++;
        }
        for(i=0;i<26;i++)
        if(hash[i]==0){
            printf("%c\n",zimu[i]);
          f=1;
            break;
        }
        if(f)continue;
        for(i='a';i<='z';i++)
        {for(j='a';j<='z';j++)
        {
            mark=0;
            yuan[0]=i;yuan[1]=j;
            yuan[2]='\0';
    
            for(k=1;k<=n;k++)
                {if(strstr(str[k],yuan)!=NULL)
                {mark=1;
                break;
                }
                }
            
            if(mark==0){printf("%c%c\n",yuan[0],yuan[1]);break;}
        
        }
        if(mark==0)break;
        }
    }

return 0;
}

### 关于 Codeforces 1853B 的题解与实现 尽管当前未提供关于 Codeforces 1853B 的具体引用内容,但可以根据常见的竞赛编程问题模式以及相关算法知识来推测可能的解决方案。 #### 题目概述 通常情况下,Codeforces B 类题目涉及基础数据结构或简单算法的应用。假设该题目要求处理某种数组操作或者字符串匹配,则可以采用如下方法解决: #### 解决方案分析 如果题目涉及到数组查询或修改操作,一种常见的方式是利用前缀和技巧优化时间复杂度[^3]。例如,对于区间求和问题,可以通过预计算前缀和数组快速得到任意区间的总和。 以下是基于上述假设的一个 Python 实现示例: ```python def solve_1853B(): import sys input = sys.stdin.read data = input().split() n, q = map(int, data[0].split()) # 数组长度和询问次数 array = list(map(int, data[1].split())) # 初始数组 prefix_sum = [0] * (n + 1) for i in range(1, n + 1): prefix_sum[i] = prefix_sum[i - 1] + array[i - 1] results = [] for _ in range(q): l, r = map(int, data[2:].pop(0).split()) current_sum = prefix_sum[r] - prefix_sum[l - 1] results.append(current_sum % (10**9 + 7)) return results print(*solve_1853B(), sep='\n') ``` 此代码片段展示了如何通过构建 `prefix_sum` 来高效响应多次区间求和请求,并对结果取模 \(10^9+7\) 输出[^4]。 #### 进一步扩展思考 当面对更复杂的约束条件时,动态规划或其他高级技术可能会被引入到解答之中。然而,在没有确切了解本题细节之前,以上仅作为通用策略分享给用户参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值