设为首页 加入收藏

TOP

Codeforces Round #290 (Div. 2)(A,B,C)(二)
2015-07-24 05:04:25 来源: 作者: 【 】 浏览:22
Tags:Codeforces Round #290 Div.
pbmcgY29uc2lzdGluZyBvZiA8ZW0+bTwvZW0+IGNoYXJhY3RlcnMsCiBleHByZXNzaW5nIGNvbG9ycyBvZiBkb3RzIGluIGVhY2ggbGluZS4gRWFjaCBjaGFyYWN0ZXIgaXMgYW4gdXBwZXJjYXNlIExhdGluIGxldHRlci48L3A+CgoKCk91dHB1dAo8cD4KT3V0cHV0IA=="Yes" if there exists a cycle, and "No" otherwise.

Sample test(s) input
3 4
AAAA
ABCA
AAAA
output
Yes
input
3 4
AAAA
ABCA
AADA
output
No
input
4 4
YYYR
BYBY
BBBY
BBBY
output
Yes
input
7 6
AAAAAB
ABBBAB
ABAAAB
ABABBB
ABAAAB
ABBBAB
AAAAAB
output
Yes
input
2 13
ABCDEFGHIJKLM
NOPQRSTUVWXYZ
output
No
Note

In first sample test all 'A' form a cycle.

In second sample there is no such cycle.

The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red).


#include 
            
             
#include 
             
               #include 
              
                #include 
               
                 #include 
                
                  #include 
                 
                   #include 
                   #include 
                   
                     using namespace std; const int inf=0x3f3f3f3f; char str[60][60]; int vis[60][60]; int jx[]= {0,1,0,-1}; int jy[]= {1,0,-1,0}; int n,m; int flag = 0; struct node { int x,y; }; void dfs(int uu,int vv,int x1,int y1) { int i; int u,v; for(i=0;i<4;i++) { if(flag==1) return ; u=uu+jx[i]; v=vv+jy[i]; if(vis[u][v]==1&&str[uu][vv]==str[u][v]&&x1!=u&&y1!=v) { printf("Yes\n"); flag=1; return ; } if(vis[u][v]==0) { if(str[uu][vv]==str[u][v] &&u>=0&&u
                    
                     =0&&v
                     
                      
C. Fox And Names time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.

After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted inlexicographical order in normal sense. But it was always true that after some modification of the order of letters in alphabet, the order of authors becomes lexicographical!

She wants to know, if there exists an order of letters in Latin alphabet such that the names on the paper she is submitting are following in the lexicographical order. If so, you should find out any such order.

Lexicographical order is defined in following way. When we compare s and t, first we find the leftmost position with differing characters: si?≠?ti. If there is no such position (i. e. s is a prefix of t or vice versa) the shortest string is less. Otherwise, we compare characters si and tiaccording to their order in alphabet.

Input

The first line contains an integer n (1?≤?n?≤?100): number of names.

Each of the following n lines contain one string namei (1?≤?|namei|?≤?100), the i-th name. Each name contains only lowercase Latin letters. All names are different.

Output

If there exists such order of letters that the given names are sorted lexicographically, output any such order as a permutation of characters 'a'?'z' (i. e. first output the first letter of the modified alphabet, then the second, and so on).

Otherwise output a single word "Impossible" (without quotes).

Sample test(s) input
3
rivest
shamir
adleman
output
bcdefghijklmnopqrsatuvwxyz
input
10
tourist
petr
wjmzbmr
yeputons
vepifanov
scottwu
oooooooooooooooo
subscriber
rowdark
tankengineer
output
Impossible
input
10
petr
egor
endagorion
feferivan
ilovetanyaromanova
kostka
dmitriyh
maratsnowbear
bredorjaguarturnik
cgyforever
output
aghjlnopefikdmbcqrstuvwxyz
input
7
car
care
careful
carefully
becarefuldontforgetsomething
otherwiseyouwillbehacked
goodluck
output
acbdefhijklmnogpqrstuvwxyz

#include 
                       
                        
#include 
                        
                          #include 
                         
                           #include 
                          
                            #include 
                           
                             #include 
                            
                              #include 
                             
                               using namespace std; int in[40]; int dis[40]; int map[40][40]; void topo() { int i,j,k; int cnt=0
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇c++ const成员函数的纠结 下一篇BZOJ 3503 CQOI 2014 和谐矩阵 高..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: