程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #290 (Div. 2)(A,B,C)

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

編輯:C++入門知識

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 colZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vci4gV2Ugd2lsbCB1c2UgZGlmZmVyZW50IHVwcGVyY2FzZSBMYXRpbiBjaGFyYWN0ZXJzIHRvIGV4cHJlc3MgZGlmZmVyZW50IGNvbG9ycy48L3A+CjxwPgpUaGUga2V5IG9mIHRoaXMgZ2FtZSBpcyB0byBmaW5kIGEgY3ljbGUgdGhhdCBjb250YWluIGRvdHMgb2Ygc2FtZSBjb2xvci4gQ29uc2lkZXIgNCBibHVlIGRvdHMgb24gdGhlIHBpY3R1cmUgZm9ybWluZyBhIGNpcmNsZSBhcyBhbiBleGFtcGxlLiBGb3JtYWxseSwgd2UgY2FsbCBhIHNlcXVlbmNlIG9mIGRvdHMgPGVtPmQ8L2VtPjEsPzxlbT5kPC9lbT4yLD8uLi4sPzxlbT5kPC9lbT48ZW0+azwvZW0+IGEgY3ljbGUgaWYKIGFuZCBvbmx5IGlmIGl0IG1lZXRzIHRoZSBmb2xsb3dpbmcgY29uZGl0aW9uOjwvcD4KPG9sPgo8bGk+ClRoZXNlIDxlbT5rPC9lbT4gZG90cyBhcmUgZGlmZmVyZW50OiBpZiA8ZW0+aTwvZW0+P6HZPzxlbT5qPC9lbT4gdGhlbiA8ZW0+ZDwvZW0+PGVtPmk8L2VtPiBpcwogZGlmZmVyZW50IGZyb20gPGVtPmQ8L2VtPjxlbT5qPC9lbT4uPGxpPgo8ZW0+azwvZW0+IGlzIGF0IGxlYXN0IDQuPGxpPgpBbGwgZG90cyBiZWxvbmcgdG8gdGhlIHNhbWUgY29sb3IuPGxpPgpGb3IgYWxsIDE/odw/PGVtPmk8L2VtPj+h3D88ZW0+azwvZW0+Py0/MTogPGVtPmQ8L2VtPjxlbT5pPC9lbT4gYW5kIDxlbT5kPC9lbT48ZW0+aTwvZW0+PyYjNDM7PzEgYXJlCiBhZGphY2VudC4gQWxzbywgPGVtPmQ8L2VtPjxlbT5rPC9lbT4gYW5kIDxlbT5kPC9lbT4xIHNob3VsZAogYWxzbyBiZSBhZGphY2VudC4gQ2VsbHMgPGVtPng8L2VtPiBhbmQgPGVtPnk8L2VtPiBhcmUgY2FsbGVkIGFkamFjZW50CiBpZiB0aGV5IHNoYXJlIGFuIGVkZ2UuCjxwPgpEZXRlcm1pbmUgaWYgdGhlcmUgZXhpc3RzIGEgY3ljbGUgb24gdGhlIGZpZWxkLjwvcD4KCgoKSW5wdXQKPHA+ClRoZSBmaXJzdCBsaW5lIGNvbnRhaW5zIHR3byBpbnRlZ2VycyA8ZW0+bjwvZW0+IGFuZCA8ZW0+bTwvZW0+ICgyP6HcPzxlbT5uPC9lbT4sPzxlbT5tPC9lbT4/odw/NTApOgogdGhlIG51bWJlciBvZiByb3dzIGFuZCBjb2x1bW5zIG9mIHRoZSBib2FyZC48L3A+CjxwPgpUaGVuIDxlbT5uPC9lbT4gbGluZXMgZm9sbG93LCBlYWNoIGxpbmUgY29udGFpbnMgYSBzdHJpbmcgY29uc2lzdGluZyBvZiA8ZW0+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;
    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;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved