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 }
  • 相关阅读:
    (数据科学学习手札33)基于Python的网络数据采集实战(1)
    (数据科学学习手札32)Python中re模块的详细介绍
    (数据科学学习手札31)基于Python的网络数据采集(初级篇)
    (数据科学学习手札30)朴素贝叶斯分类器的原理详解&Python与R实现
    (数据科学学习手札29)KNN分类的原理详解&Python与R实现
    (数据科学学习手册28)SQL server 2012中的查询语句汇总
    牛客3 F/G 牛牛的Link Power |线段树区间修改
    牛客2-H施魔法|线段树优化dp,维护区间最小值
    2020牛客寒假算法基础集训营1
    友情链接
  • 原文地址:https://www.cnblogs.com/acmicky/p/3221426.html
Copyright © 2011-2022 走看看