Codeforces Round #217前三题(一)

2014-11-24 07:11:01 · 作者: · 浏览: 2
A. Rook, Bishop and King time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by a pair of integers (r, c)― the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules:

  • A rook moves any number of fields horizontally or vertically.
  • A bishop moves any number of fields diagonally.
  • A king moves one field in any direction ― horizontally, vertically or diagonally.

    \The pieces move like that

    < http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ClBldHlhIGlzIHRoaW5raW5nIGFib3V0IHRoZSBmb2xsb3dpbmcgcHJvYmxlbTogd2hhdCBtaW5pbXVtIG51bWJlciBvZiBtb3ZlcyBpcyBuZWVkZWQgZm9yIGVhY2ggb2YgdGhlc2UgcGllY2VzIHRvIG1vdmUgZnJvbSBmaWVsZCg8ZW0+cjwvZW0+PHN1YiBjbGFzcz0="lower-index">1, c1) to field (r2, c2) At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.

    Input

    The input contains four integers r1, c1, r2, c2 (1 ≤ r1, c1, r2, c2 ≤ 8) ― the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.

    You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.

    Output

    Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number.

    Sample test(s) input
    4 3 1 6
    
    output
    2 1 3
    
    input
    5 5 5 6
    
    output
    1 0 1
    

    题目大意:从一个点到另一个点,经过三种变换,问分别用每种变换可以到的最小步数。第一种是横着竖着走,答案直接分为1,2即可。第二种斜着走,答案分为1 2 0三种,0表示到达不了,画一个方格走一下就懂了。坑在了第三种前面两种每次走的路程任意,而第三种每次只能走一步,可以斜着横着竖着走。竟然没心没肺的写了个bfs......直接比较横纵坐标差值,谁大就可以了。。这个题目和昨天晚上打的cf题目很相似,不过昨天晚上那个需要判断越界。


    题目地址:A. Rook, Bishop and King


    AC代码:

    #include
        
         
    #include
         
           #include
          
            #include
           
             #include
            
              #include
             
               using namespace std; int a,b,c,d; int visi[10][10]; int res[10][10]; int dir[8][2]={{-1,0},{1,0},{0,1},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}}; void bfs() { queue
              
                mq; mq.push(a*10+b); //cout<
               
                =1&&cx<=8&&cy>=1&&cy<=8&&!visi[cx][cy]) { res[cx][cy]=res[tx][ty]+1; visi[cx][cy]=1; mq.push(cx*10+cy); } } } } int main() { int s1,s2; while(cin>>a>>b>>c>>d) { if(a==c||b==d) s1=1; else s1=2; if(a+b==c+d||a+d==b+c) s2=1; else if(abs(a+b-c-d)%2==0) s2=2; else s2=0; bfs(); printf("%d %d %d\n",s1,s2,res[c][d]); } return 0; }
               
              
             
            
           
          
         
        



    B. Berland Bingo time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

    Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers.

    During the game the host takes numbered balls one by one from a bag. He reads the number aloud in a high and clear voice and then puts the ball away. All participants cross out the number if it occurs on their cards. The person who crosses out all numbers from his card first, wins. If multiple people cross out all numbers from their cards at the same time, there are no winners in the game. At the beginning of the game the bag contains 100 balls numbered 1 through 100, the numbers of all balls are distinct.

    You are given the cards for each player. Write a program that determines whether a player can win the game at the most favorable for him scenario or not.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 100) ― the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, 2, ..., ai, mi (1 ≤ ai, k ≤ 100) ― the numbers on the i-th player's card. The numbers in the lines are separated by single spaces.

    It is guaranteed that all the numbers on each card are distinct.

    Output

    Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.

    Sample test(s) input
    3
    1 1
    3 2 4 1
    2 10 11
    
    output
    YES
    NO
    YES
    
    input
    2
    1 1
    1 1
    
    output
    NO
    NO
    


    题目大意:每次有n个人,每个人手上拿了若干卡片,每个卡片编号不一样,当然同一个人手里的编号不会重复。然后一个人在点号,他报到哪一个号,持有相应卡片的人就把那张卡片划掉,最先被划掉所有卡片的人会得到奖励,问谁有可能获得奖励,如果可能输出yes,否则输出no。


    解题思路:可以直接判断集合包含子集的问题,每个人是一个集合,集合里的元素就是自己的卡片,可以包含别人的集合,那么你就是no。


    题目地址:A. Rook, Bishop and King


    AC代码:

    #include
        
         
    #include
         
           #include
          
            #include
           
             #include
            
              #include
             
               using namespace std; int a[102]; int visi[102][102]; int t[102]; int n; int cal(int a,int b) { int i; for(i=1;i<=100;i++) { if(!visi[a][i]&&visi[b][i]) return 0; } return 1; } void solve() { int i,j; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i==j) continue; if(cal(i,j)) t[i]=0; } } } int main() { int d,i,x,j; while(cin>>n) { memset(visi,0,sizeof(visi)); for(i=1;i<=n;i++) { scanf("%d",&d); for(j=1;j<=d;j++) { scanf("%d",&x); visi[i][x]=1; } } for(i=1;i<=n;i++) t[i]=1; solve(); for(i=1;i<=n;i++) { if(t[i]==1) puts("YES"); else puts("NO"); } } return 0; }
             
            
           
          
         
        


    C. Mittens time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

    A Christmas party in city S. had n children. All children came in mittens. The mittens can be of different colors, but each child had the left and the right mitten of the same color. Let's say that the colors of the mittens are numbered with integers from 1 to m, and the children are nu