hdu 1057 A New Growth Industry

简介:

1057 A New Growth Industry

 

      简单模拟题,貌似uva上也有

      注意数据间要有空行

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <cstdio>
#include <cstring>
const char o[4]={'.','!','X','#'};
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
int day,now[20][20],next[20][20],change[16];
int main()
{
    int T,i,j,k,x,y,temp;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&day);
        for(i=0;i<16;i++)scanf("%d",&change[i]);
        for(i=0;i<20;i++)
          for(j=0;j<20;j++)
             scanf("%d",&now[i][j]);
        while(day--)
        {
            for(i=0;i<20;i++)
             for(j=0;j<20;j++)
             {
                temp=now[i][j];
                for(k=0;k<4;k++)
                {
                    x=i+dir[k][0];
                    y=j+dir[k][1];
                    if(x<0||x>=20||y<0||y>=20)continue;
                    temp+=now[x][y];
                }
                next[i][j]=now[i][j]+change[temp];
                if(next[i][j]<0)next[i][j]=0;
                if(next[i][j]>3)next[i][j]=3;
             }
            memcpy(now,next,sizeof(next));
        }
        for(i=0;i<20;i++,puts(""))
         for(j=0;j<20;j++)
             printf("%c",o[now[i][j]]);
        if(T)puts("");
    }
    return 0;
}


 

目录
相关文章
|
2月前
|
人工智能 算法 ice
【2024美赛】D题(中英文):五大湖水资源问题Problem Problem D: Great Lakes Water Problem
【2024美赛】D题(中英文):五大湖水资源问题Problem Problem D: Great Lakes Water Problem
30 1
|
5月前
Leetcode 365. Water and Jug Problem
一句话理解题意:有容积为x和y升的俩水壶,能不能量出z升的水。 我刚开始看到这题,立马就想了下暴力搜索的可能性,但考虑了下数据大小,立马放弃这个暴力的想法,于是意识到肯定有比较简单的数学方法,其实我自己没想到,后来看还是看了别人的代码,很多博客都直接给出了解法, 但没介绍为什么能这么解。所以我决定解释下我自己的思路。
26 0
|
11月前
The Preliminary Contest for ICPC China Nanchang National Invitational A题 PERFECT NUMBER PROBLEM
The Preliminary Contest for ICPC China Nanchang National Invitational A题 PERFECT NUMBER PROBLEM
49 0
LeetCode 365. Water and Jug Problem
有两个容量分别为 x升 和 y升 的水壶以及无限多的水。请判断能否通过使用这两个水壶,从而可以得到恰好 z升 的水?
60 0
LeetCode 365. Water and Jug Problem
HDU-1057,A New Growth Industry(理解题意)
HDU-1057,A New Growth Industry(理解题意)
|
机器学习/深度学习 自然语言处理

热门文章

最新文章