Codeforces Round #290 (Div. 2)(A,B,C)

A. Fox And Snake
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.

A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1, m), then goes down 2 rows to (3, m), then goes left to (3, 1) and so on.

Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').

Consider sample tests in order to understand the snake pattern.

Input

The only line contains two integers: n and m (3 ≤ n, m ≤ 50).

n is an odd number.

Output

Output n lines. Each line should contain a string consisting of m characters. Do not output spaces.

Sample test(s)
input
3 3
output
###
..#
###
input
3 4
output
####
...#
####
input
5 3
output
###
..#
###
#..
###
input
9 9
output
#########
........#
#########
#........
#########
........#
#########
#........
#########

include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
const int inf=0x3f3f3f3f;
int main()
{
    int n,m,i,j;
    while(~scanf("%d %d",&n,&m)) {
        for(i=1; i<=n; i++) {
            if(i%2==1) {
                for(j=1; j<=m; j++)
                    printf("#");
                printf("\n");
            } else {
                if(i%2==0&&i%4==0) {
                    printf("#");
                    for(j=2; j<=m; j++)
                        printf(".");
                    printf("\n");
                } else if(i%2==0&&i%4!=0) {
                    for(j=1; j
B. Fox And Two Dots
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n × m cells, like this:

Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.

The key of this game is to find a cycle that contain dots of same color. Consider 4 blue dots on the picture forming a circle as an example. Formally, we call a sequence of dots d1, d2, ..., dk a cycle if and only if it meets the following condition:

  1. These k dots are different: if i ≠ j then di is different from dj.
  2. k is at least 4.
  3. All dots belong to the same color.
  4. For all 1 ≤ i ≤ k - 1di and di + 1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge.

Determine if there exists a cycle on the field.

Input

The first line contains two integers n and m (2 ≤ n, m ≤ 50): the number of rows and columns of the board.

Then n lines follow, each line contains a string consisting of m characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.

Output

Output "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;
    for(i=0;i<26;i++)
    for(j=0;j<26;j++){
        if(in[j]==0){
            dis[cnt++]=j;
            in[j]=-1;
            for(k=0;k<26;k++){
                if(map[j][k]==1)
                    in[k]--;
            }
            break;
        }
    }
    if(cnt<26)
        printf("Impossible\n");
    else{
        for(i=0;i<26;i++)
            printf("%c",dis[i]+'a');
    }
}
int main()
{
    int n,i,j;
    int u,v;
    int flag;
    char str[110][110];
    while(~scanf("%d",&n)){
            flag=0;
        for(i=0;ilen2){
                    for(j=0;str[i-1][j]!='\0';j++){
                        if(j==len2){
                            flag=1;
                            break;
                        }
                        if(str[i][j]!=str[i-1][j]){
                            u=str[i-1][j]-'a';
                            v=str[i][j]-'a';
                            if(!map[u][v]){
                                map[u][v]=1;
                                in[v]++;
                            }
                            break;
                        }

                    }
                }
                else if(len2>len1){
                    for(j=0;str[i-1][j]!='\0';j++){
                        if(j==len1){
                            flag=1;
                            break;
                        }
                        if(str[i][j]!=str[i-1][j]){
                            u=str[i-1][j]-'a';
                            v=str[i][j]-'a';
                            if(!map[u][v]){
                                map[u][v]=1;
                                in[v]++;
                            }
                            break;
                        }

                    }
                }
                else{
                    for(j=0;str[i-1][j]!='\0';j++){
                        if(j==len2){
                            break;
                        }
                        if(str[i][j]!=str[i-1][j]){
                            u=str[i-1][j]-'a';
                            v=str[i][j]-'a';
                            if(!map[u][v]){
                                map[u][v]=1;
                                in[v]++;
                            }
                            break;
                        }

                    }
                }

            }
            if(flag){
               printf("Impossible\n");
               continue;
            }
                topo();
    }
    return 0;
}


你可能感兴趣的:(CodeForces)