CodeForces 278BNew Problem
来源:互联网 发布:可信的网络兼职 编辑:程序博客网 时间:2024/06/05 22:43
Description
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 originalif 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 substrings[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 Input
5threehorsesgoodsubstringssecretprimematrixbeautifulyear
j
4aabdefghijklmnopqrstuvwxyzc
ab
Hint
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.
题意:给你一个数n,然后n行,表示文章标题,现在让你求的是最短的起初的文章标题,这个标题要求n个文章标题中都不包含(也就是不是子串)。
思路:可以看到n很小,长度也很小,直接暴力。从长度为1的串依次增加字典序,依次枚举,只要n个串中不包含这个串就是答案。
#include <iostream>#include <bits/stdc++.h>using namespace std;char s[30][25];char a[30];int n;int flag=0;void dfs(int l,int goal){ int i,j; if(l==goal) { a[l]=0; for(j=0; j<n; ++j) { if(strstr(s[j],a))break;//如果包含说明不符合条件 } if(j==n)//如果符合条件 { puts(a); flag=1; } return; } for(i=0; i<=25; ++i) { a[l]=i+'a'; dfs(l+1,goal); if(flag)return; }}int main(){ int i; scanf("%d",&n); for(i=0; i<n; ++i) { scanf("%s",s[i]); } for(i=1;;++i) { dfs(0,i); if(flag)break; } return 0;}
- CodeForces 278BNew Problem
- CodeForces 628BNew Skateboard-数学水题
- CodeForces 611BNew Year and Old Property
- CodeForces 611BNew Year and Old Property(模拟)
- codeforces 278B New Problem
- codeforces 278B New Problem 字符串查找
- Problem - 216B - Codeforces
- Codeforces CROC problem C
- Problem - 218B - Codeforces
- Problem - 152A - Codeforces
- codeforces problem/244/A
- codeforces problem/415/A
- codeforces problem/408/B
- codeforces. problem/408/A
- Codeforces Problem - 50B
- Problem - 376B - Codeforces
- problem - 616B -codeforces
- CodeForces 17ANoldbach problem
- eclipse maven 导出项目依赖的jar包
- wireshark ts流分析--简明步骤
- C++——算法基础之动态查找表2——平衡二叉树(插入)
- leetcode No131. Palindrome Partitioning
- 前端优化的规则
- CodeForces 278BNew Problem
- codeforces 354A Vasya and Robot [思维]
- 关于Window和WindowManager的一点愚见(添加,删除,更新)
- Android 动态改变Layout的大小
- linux常用操作命令大全
- 第二周项目0--宣告“主权”
- 分布式缓存系统Memcache简介与实践
- 括号配对问题
- 浅析线程池