zoukankan      html  css  js  c++  java
  • POJ

    初看题目时就发了个错误,我因为没有耐心看题而不了解题目本身的意思,找不到做题的突破口,即使看了一些题解,还是没有想到方法。

    后来在去问安叔,安叔一语道破天机,问我有没有搞清题目的意思,我才恍然大悟,做题当然要先搞懂题目意思,不然做什么题呢!以后一定要再三注意!而且要把每一个细节都注意到!

    POJ - 2339 Rock, Scissors, Paper

    Time Limit: 5000MS

     

    Memory Limit: 65536KB

     

    64bit IO Format: %I64d & %I64u

     

    Description

    Bart's sister Lisa has created a new civilization on a two-dimensional grid. At the outset each grid location may be occupied by one of three life forms: Rocks, Scissors, or Papers. Each day, differing life forms occupying horizontally or vertically adjacent grid locations wage war. In each war, Rocks always defeat Scissors, Scissors always defeat Papers, and Papers always defeat Rocks. At the end of the day, the victor expands its territory to include the loser's grid position. The loser vacates the position. 
    Your job is to determine the territory occupied by each life form after n days.

    Input

    The first line of input contains t, the number of test cases. Each test case begins with three integers not greater than 100: r and c, the number of rows and columns in the grid, and n. The grid is represented by the r lines that follow, each with c characters. Each character in the grid is R, S, or P, indicating that it is occupied by Rocks, Scissors, or Papers respectively.

    Output

    For each test case, print the grid as it appears at the end of the nth day. Leave an empty line between the output for successive test cases.

    Sample Input

    2

    3 3 1

    RRR

    RSR

    RRR

    3 4 2

    RSPR

    SPRS

    PRSP

     

    Sample Output

    RRR

    RRR

    RRR

     

    RRRS

    RRSP

    RSPR

     

    Source

    Waterloo local 2003.01.25

     

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<math.h>
     4 #include<stdlib.h>
     5 char toda[105][105];
     6 char tomo[105][105];
     7 int main()
     8 {
     9     int t = 0, r = 0, c = 0, n = 0, i = 0, j = 0;
    10     scanf("%d", &t);
    11     while(t--) {
    12         scanf("%d%d%d", &r, &c, &n);
    13         for(i = 0; i < r; i++) {
    14             scanf("%s", toda[i]);
    15         }
    16         for(i = 0; i < r; i++) {
    17             for(j = 0; j < c; j++) {
    18                 tomo[i][j] = toda[i][j];
    19             }
    20         }
    21         while(n--) {
    22             for(i = 0; i < r; i++) {
    23                 for(j = 0; j < c; j++) {
    24                     if(toda[i][j] == 'R') {
    25                         if(j+1 < c && toda[i][j+1] == 'S')
    26                             tomo[i][j+1] = 'R';
    27                         if(i-1 >= 0 && toda[i-1][j] == 'S')
    28                             tomo[i-1][j] = 'R';
    29                         if(j-1 >= 0 && toda[i][j-1] == 'S')
    30                             tomo[i][j-1] = 'R';
    31                         if(i+1 < r && toda[i+1][j] == 'S')
    32                             tomo[i+1][j] = 'R';
    33                     }
    34                     else if(toda[i][j] == 'S') {
    35                         if(j+1 < c && toda[i][j+1] == 'P')
    36                             tomo[i][j+1] = 'S';
    37                         if(i-1 >= 0 && toda[i-1][j] == 'P')
    38                             tomo[i-1][j] = 'S';
    39                         if(j-1 >= 0 && toda[i][j-1] == 'P')
    40                             tomo[i][j-1] = 'S';
    41                         if(i+1 < r && toda[i+1][j] == 'P')
    42                             tomo[i+1][j] = 'S';
    43                     }
    44                     else {
    45                         if(j+1 < c && toda[i][j+1] == 'R')
    46                             tomo[i][j+1] = 'P';
    47                         if(i-1 >= 0 && toda[i-1][j] == 'R')
    48                             tomo[i-1][j] = 'P';
    49                         if(j-1 >= 0 && toda[i][j-1] == 'R')
    50                             tomo[i][j-1] = 'P';
    51                         if(i+1 < r && toda[i+1][j] == 'R')
    52                             tomo[i+1][j] = 'P';
    53                     }
    54                 }
    55             }
    56             for(i = 0; i < r; i++) {
    57                 for(j = 0; j < c; j++) {
    58                     toda[i][j] = tomo[i][j];
    59                 }
    60             }
    61         }
    62         for(i = 0; i < r; i++) {
    63             for(j = 0; j < c; j++) {
    64                 printf("%c", toda[i][j]);
    65             }
    66             printf("
    ");
    67         }
    68         if(n) printf("
    ");
    69     }
    70     return 0;
    71 }
  • 相关阅读:
    HTML a标签的href 属性 tel 点击可以直接拨打电话 ( 移动端 )
    【集群实战】NFS网络文件共享服务3-相关知识补充(showmount,exports,rpc)
    【集群实战】NFS网络文件共享服务2-mount挂载(参数,优化)
    Linux发送邮件命令mail,mutt
    【集群实战】NFS服务常见故障排查和解决方法
    【集群实战】NFS网络文件共享服务
    【集群实战】Rsync试题-异机数据备份解决方案
    【集群实战】Rsync常见错误总结
    【集群实战】Rsync数据同步工具
    【shell】Shell变量基础及深入
  • 原文地址:https://www.cnblogs.com/acmicky/p/3221426.html
Copyright © 2011-2022 走看看