zoukankan      html  css  js  c++  java
  • The 13th Zhejiang Provincial Collegiate Programming Contest

    Apples and Ideas

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    "If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas." - George Bernard Shaw

    Now Alice has A apples and B ideas, while Bob has C apples and D ideas, what will they have if they exchange all things?

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The only line contains four integers A, B, C, D (0 <= A, B, C, D <= 100) - as the problem described.

    Output

    For each test case, output two lines. First line contains two integers, indicating the number of Alice's apples and ideas; second line contains two integers, indicating the number of Bob's apples and ideas.

    Sample Input

    4
    0 0 5 30
    20 25 20 0
    20 25 20 15
    20 25 25 30
    

    Sample Output

    5 30
    0 30
    20 25
    20 25
    20 40
    20 40
    25 55
    20 55
     1 /*A*/
     2 #include<cstdio>
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     int T;
     8     scanf("%d",&T);
     9     while(T--)
    10     {
    11         int A,B,C,D;
    12         scanf("%d%d%d%d",&A,&B,&C,&D);
    13         int k=B+D;
    14         printf("%d %d
    ",C,k);
    15         printf("%d %d
    ",A,k);
    16     }
    17     return 0;
    18  } 
    View Code
    Defuse the Bomb

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    The bomb is about to explode! Please defuse it as soon as possible!

    There is a display showing a number from 1 to 4 on the bomb. Besides this, there are 4 buttons under the display. Each button is labeled by a number from 1 to 4. The numbers on the buttons are always distinct.

    There are 5 defusing stages in total. Pressing the correct button can progress the bomb to the next defusing stage. The number on the display and the number on each button may be different in different stages. The bomb will be defused only when all 5 defusing stages get passed. Pressing the incorrect button will cause the bomb to explode immediately. Be careful!

    Here is the detailed bomb defusing manual. Button positions are ordered from left to right.

    Stage 1:

    • If the display is 1, press the button in the second position.
    • If the display is 2, press the button in the second position.
    • If the display is 3, press the button in the third position.
    • If the display is 4, press the button in the fourth position.

    Stage 2:

    • If the display is 1, press the button labeled "4".
    • If the display is 2, press the button in the same position as you pressed in stage 1.
    • If the display is 3, press the button in the first position.
    • If the display is 4, press the button in the same position as you pressed in stage 1.

    Stage 3:

    • If the display is 1, press the button with the same label you pressed in stage 2.
    • If the display is 2, press the button with the same label you pressed in stage 1.
    • If the display is 3, press the button in the third position.
    • If the display is 4, press the button labeled "4".

    Stage 4:

    • If the display is 1, press the button in the same position as you pressed in stage 1.
    • If the display is 2, press the button in the first position.
    • If the display is 3, press the button in the same position as you pressed in stage 2.
    • If the display is 4, press the button in the same position as you pressed in stage 2.

    Stage 5:

    • If the display is 1, press the button with the same label you pressed in stage 1.
    • If the display is 2, press the button with the same label you pressed in stage 2.
    • If the display is 3, press the button with the same label you pressed in stage 4.
    • If the display is 4, press the button with the same label you pressed in stage 3.

    Input

    There are multiple test cases. The first line of input is an integer T indicating the number of test cases. For each test case:

    There are 5 lines. Each line contains 5 integers D, B1, B2, B3, B4 indicating the number on the display and the numbers on the buttons respectively. The i-th line correspond to the i-th stage.

    Output

    For each test case, output 5 lines. The i-th line contains two integers indicating the position and the label of the correct button for the i-th stage.

    Sample Input

    1
    4 2 1 3 4
    2 2 4 3 1
    4 3 1 4 2
    4 3 4 2 1
    2 3 1 2 4
    

    Sample Output

    4 4
    4 1
    3 4
    4 1
    2 1
    

    Hint

    Keep talking with your teammates and nobody explodes!

      1 #include<iostream>
      2 #include<cstdio>
      3 using namespace std;
      4 int a[6],b[6],c[6],d[6],e[6];
      5 int main()
      6 {
      7     int t;
      8     cin>>t;
      9     while(t--)
     10     {
     11         int a1,b1,c1,d1,e1,a2,b2,c2,d2,e2;
     12             cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
     13             cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4];
     14             cin>>c[0]>>c[1]>>c[2]>>c[3]>>c[4];
     15             cin>>d[0]>>d[1]>>d[2]>>d[3]>>d[4];
     16             cin>>e[0]>>e[1]>>e[2]>>e[3]>>e[4];
     17             for(int i=1;i<=5;i++)
     18             {
     19             if(i==1)
     20             {  
     21                 if(a[0]==1||a[0]==2)
     22                 {
     23                     printf("2 %d
    ",a[2]);
     24                     a1=2;a2=a[2];
     25                 }
     26                 else if(a[0]==3)
     27                 {
     28                     printf("3 %d
    ",a[3]);
     29                     a1=3;a2=a[3];
     30                 }
     31                 else if(a[0]==4)
     32                 {
     33                     printf("4 %d
    ",a[4]);
     34                     a1=4;a2=a[4];
     35                 }
     36             }
     37             if(i==2)
     38             {    
     39                 if(b[0]==1)
     40                 {
     41                     int i;
     42                     for(i=1;i<=4;i++)
     43                         if(b[i]==4)
     44                             printf("%d 4
    ",i),b1=i;
     45                     b2=4;
     46                 }
     47                 else if(b[0]==2)
     48                 {
     49                     printf("%d %d
    ",a1,b[a1]);
     50                     b1=a1;b2=b[a1];
     51                 }
     52                 else if(b[0]==3)
     53                 {
     54                     printf("1 %d
    ",b[1]);
     55                     b1=1;b2=b[1];
     56                 }
     57                 else
     58                 {
     59                     printf("%d %d
    ",a1,b[a1]);
     60                     b1=a1;b2=b[a1];    
     61                 }
     62                 
     63             }
     64             if(i==3)
     65             {
     66                 if(c[0]==1)
     67                 {
     68                     int i;
     69                     for(i=1;i<=4;i++)
     70                         if(c[i]==b2)
     71                             printf("%d %d
    ",i,b2),c1=i;
     72                     c2=b2;
     73                 }
     74                 else if(c[0]==2)
     75                 {
     76                     int i;
     77                     for(i=1;i<=4;i++)
     78                         if(c[i]==a2)
     79                             printf("%d %d
    ",i,a2),c1=i;
     80                     c2=a2;
     81                 }
     82                 else if(c[0]==3)
     83                 {
     84                     printf("3 %d
    ",c[3]);
     85                     c1=3;c2=c[3];
     86                 }
     87                 else
     88                 {
     89                     int i;
     90                     for(i=1;i<=4;i++)
     91                         if(c[i]==4)
     92                             printf("%d 4
    ",i),c1=i;
     93                     c2=4;        
     94                 }
     95             }
     96             if(i==4)
     97             {
     98                 if(d[0]==1)
     99                 {
    100                     printf("%d %d
    ",a1,d[a1]);
    101                     d1=a1;d2=d[a1];
    102                 }
    103                 else if(d[0]==2)
    104                 {
    105                     printf("1 %d
    ",d[1]);
    106                     d1=1;d2=d[1];
    107                 }
    108                 else 
    109                 {
    110                     printf("%d %d
    ",b1,d[b1]);
    111                     d1=b1;d2=d[b1];
    112                 }        
    113             }
    114             if(i==5)
    115             {
    116                 if(e[0]==1)
    117                 for(int i=1;i<=4;i++)
    118                 {
    119                     if(e[i]==a2)
    120                     {
    121                         printf("%d %d
    ",i,a2);
    122                         e1=i;e2=a2;
    123                     }
    124                 }
    125                 if(e[0]==2)
    126                 for(int i=1;i<=4;i++)
    127                 {
    128                     if(e[i]==b2)
    129                     {
    130                         printf("%d %d
    ",i,b2);
    131                         e1=i;e2=b2;
    132                     }
    133                 }
    134                 if(e[0]==3)
    135                 for(int i=1;i<=4;i++)
    136                 {
    137                     if(e[i]==d2)
    138                     {
    139                         printf("%d %d
    ",i,d2);
    140                         e1=i;e2=b2;
    141                     }
    142                 }
    143                 if(e[0]==4)
    144                 for(int i=1;i<=4;i++)
    145                 {
    146                     if(e[i]==c2)
    147                     {
    148                         printf("%d %d
    ",i,c2);
    149                         e1=i;e2=c2;
    150                     }
    151                 }
    152             }
    153         }
    154     }
    155     return 0;
    156 }
    View Code
    People Counting

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    In a BG (dinner gathering) for ZJU ICPC team, the coaches wanted to count the number of people present at the BG. They did that by having the waitress take a photo for them. Everyone was in the photo and no one was completely blocked. Each person in the photo has the same posture. After some preprocessing, the photo was converted into a H×W character matrix, with the background represented by ".". Thus a person in this photo is represented by the diagram in the following three lines:

    .O.
    /|
    (.)
    

    Given the character matrix, the coaches want you to count the number of people in the photo. Note that if someone is partly blocked in the photo, only part of the above diagram will be presented in the character matrix.

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first contains two integers H, W (1 ≤ H, W ≤ 100) - as described above, followed by H lines, showing the matrix representation of the photo.

    Output

    For each test case, there should be a single line, containing an integer indicating the number of people from the photo.

    Sample Input

    2
    3 3
    .O.
    /|
    (.)
    3 4
    OOO(
    /|\
    ()))
    

    Sample Output

    1
    4
     1 /*I*/
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 int vis[200][200];
     7         char ma[200][200];
     8 int check(int i,int j,char c)
     9 {
    10     
    11     if(c=='O')
    12     {
    13                                                 if(ma[i][j]=='O')vis[i][j]=1;
    14         if(ma[i+1][j-1]=='/')vis[i+1][j-1]=1;if(ma[i+1][j]=='|')vis[i+1][j]=1;if(ma[i+1][j+1]=='\')vis[i+1][j+1]=1;
    15         if(ma[i+2][j-1]=='(')vis[i+2][j-1]=1;                                   if(ma[i+2][j+1]==')')vis[i+2][j+1]=1;
    16         return 1;
    17     }
    18     else if(c=='/')
    19     {
    20                                      if(ma[i-1][j+1]=='O')vis[i-1][j+1]=1;
    21         if(ma[i][j]=='/')vis[i][j]=1;if(ma[i][j+1]=='|')vis[i][j+1]=1;if(ma[i][j+2]=='\')vis[i][j+2]=1;
    22         if(ma[i+1][j]=='(')vis[i+1][j]=1;                              if(ma[i+1][j+2]==')')vis[i+1][j+2]=1;
    23         return 1;
    24     }
    25     else if(c=='|')
    26     {
    27                                            if(ma[i-1][j]=='O')vis[i-1][j]=1;
    28         if(ma[i][j-1]=='/')vis[i][j-1]=1;if(ma[i][j]=='|')vis[i][j]=1;if(ma[i][j+1]=='\')vis[i][j+1]=1;
    29         if(ma[i+1][j-1]=='(')vis[i+1][j-1]=1;                            if(ma[i+1][j+1]==')')vis[i+1][j+1]=1;
    30         return 1;
    31     }
    32     else if(c=='\')
    33     {
    34                                            if(ma[i-1][j-1]=='O')vis[i-1][j-1]=1;
    35         if(ma[i][j-2]=='/')vis[i][j-2]=1;if(ma[i][j-1]=='|')vis[i][j-1]=1;if(ma[i][j]=='\')vis[i][j]=1;
    36         if(ma[i+1][j-2]=='(')vis[i+1][j-2]=1;                             if(ma[i+1][j]==')')vis[i+1][j]=1;
    37         return 1;
    38     }
    39     else if(c=='(')
    40     {
    41                                            if(ma[i-2][j+1]=='O')vis[i-2][j+1]=1;
    42         if(ma[i-1][j]=='/')vis[i-1][j]=1;if(ma[i-1][j+1]=='|')vis[i-1][j+1]=1;if(ma[i-1][j+2]=='\')vis[i-1][j+2]=1;
    43         if(ma[i][j]=='(')vis[i][j]=1;                                           if(ma[i][j+2]==')')vis[i][j+2]=1;
    44         return 1;
    45     }
    46     else if(c==')')
    47     {
    48                                               if(ma[i-2][j-1]=='O')vis[i-2][j-1]=1;
    49         if(ma[i-1][j-2]=='/')vis[i-1][j-2]=1;if(ma[i-1][j-1]=='|')vis[i-1][j-1]=1;if(ma[i-1][j]=='\')vis[i-1][j]=1;
    50         if(ma[i][j-2]=='(')vis[i][j-2]=1;                                           if(ma[i][j]==')')vis[i][j]=1;
    51         return 1;
    52     }
    53     else
    54     {
    55         vis[i][j]=1;
    56         return 0;
    57     }
    58 }
    59 int main()
    60 {
    61     int T;
    62     scanf("%d",&T);
    63     while(T--)
    64     {
    65 
    66         int n,m;
    67         scanf("%d%d",&n,&m);
    68         memset(ma,0,sizeof(ma));
    69         for(int i=10;i<n+10;i++)
    70             scanf("%s",ma[i]+10);
    71         memset(vis,0,sizeof(vis));
    72         int ans=0;
    73         for(int i=10;i<n+10;i++)
    74         {
    75             for(int j=10;j<m+10;j++)
    76             {
    77                 if(vis[i][j]==0)
    78                 {
    79                     ans+=check(i,j,ma[i][j]);
    80                     
    81                 }
    82             }
    83         }
    84         printf("%d
    ",ans);
    85     }
    86     return 0;
    87 }
    View Code
    Very Happy Great BG

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    The summer training of ZJU ICPC in July is about to end. To celebrate this great and happy day, the coach of ZJU ICPC Team decided to BG everyone!

    After a brief discussion, they decided to go to Lou Wai Lou to have a great dinner. Each team member can bring some friends with him/her. Of course, they need to tell the coach the number of friends they will bring.

    Now the coach wants to know the total number of participants (excluding the coach himself). Please tell him.

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first line contains an integer N (1 <= N <= 40) - the number of ZJU ICPC members.

    The second line contains N non-negative integers, the i-th integer indicates the number of friends (< 1000) that the i-th team member will bring.

    Output

    For each test case, output the total number of participants.

    Sample Input

    4
    5
    0 0 1 2 3
    1
    0
    10
    1 2 3 4 5 6 7 8 9 10
    2
    5 3
    

    Sample Output

    11
    1
    65
    10
     1 /*L*/
     2 #include<iostream>
     3 using namespace std;
     4 int main()
     5 {
     6     int t,n;
     7     cin>>t;
     8     while(t--)
     9     {
    10         int x=0;
    11         cin>>n;
    12         int sum=n;
    13         for(int i=0;i<n;i++)
    14         {
    15         
    16         cin>>x;
    17         sum+=x;
    18         }
    19         cout<<sum<<endl;
    20     }
    21 }
    View Code
  • 相关阅读:
    修改文件小练习
    登录、注册、删除小练习
    自动生成用户名和密码
    自动生成密码文件
    监控日志被攻击情况-小练习
    随机函数_手机自动生成小练习
    as与c++的反射机制对比
    as中的陷阱
    关于as中的事件与回调函数
    身份证号码验证
  • 原文地址:https://www.cnblogs.com/yepiaoling/p/5425105.html
Copyright © 2011-2022 走看看