HDU 1057 - A New Growth Industry

简单的模拟.

给定天数n,给定D[0]~D[15]给定一个20*20的矩阵。每个格子内有一个0~3的数字,表示细菌数。每天,每个格子将加上D[k],k表示这个格子以及上下左右相邻格子的细菌之和(矩阵外算作0个,每格细菌个数不能超过3,不能低于0)。问n天后的细菌情况。
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int t,n;
 5 int d[16];
 6 int map[20][20],tmp[20][20];
 7 char arr[]={‘.‘,‘!‘,‘X‘,‘#‘};
 8 int main()
 9 {
10     scanf("%d",&t);
11     while(t--)
12     {
13         scanf("%d",&n);
14         for(int i=0;i<16;i++) scanf("%d",&d[i]);
15         for(int i=0;i<20;i++)
16             for(int j=0;j<20;j++)
17                 scanf("%d",&map[i][j]);
18         int sum;
19         while(n--)
20         {
21             for(int i=0;i<20;i++)
22                 for(int j=0;j<20;j++) tmp[i][j]=map[i][j];
23             for(int i=0;i<20;i++)
24                 for(int j=0;j<20;j++)
25                 {
26                     sum=tmp[i][j];
27                     if(i>0) sum+=tmp[i-1][j];
28                     if(i<19) sum+=tmp[i+1][j];
29                     if(j>0) sum+=tmp[i][j-1];
30                     if(j<19) sum+=tmp[i][j+1];
31                     map[i][j]+=d[sum];
32                     map[i][j]= map[i][j]>3? 3:map[i][j];
33                     map[i][j]= map[i][j]<0? 0:map[i][j];
34                 }
35         }
36         for(int i=0;i<20;i++)
37         {
38             for(int j=0;j<20;j++)
39                 cout<<arr[map[i][j]];
40             cout<<endl;
41         }
42         if(t) puts("");
43     }
44 }
时间: 2024-08-25 00:08:40

HDU 1057 - A New Growth Industry的相关文章

HDU ACM 1057 A New Growth Industry 简单模拟

题意:给一个天数N,求20*20方阵内细菌的变化情况.每次变化加上一个d[k],d数组有给定的16个数.k是某个格子它本身加上它上下左右的四个数. 简单模拟题. 分析: #include<iostream> using namespace std; int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; char den[]=".!X#"; int D[16]; int map[20][20],tmp[20][20]; void Fun() {

【HDOJ】1057 A New Growth Industry

纯粹的模拟题目. 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 #define MAXN 20 6 #define MAXM 16 7 8 char tb[] = ".!X#"; 9 int D[MAXM]; 10 int map[2][MAXN+2][MAXN+1]; 11 int dir[4][2] = { 12 {-1,0}, {1,0}, {0,1}, {0

HDOJ1057 A New Growth Industry 【模拟】

A New Growth Industry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1197    Accepted Submission(s): 474 Problem Description A biologist experimenting with DNA modification of bacteria has fou

1051A New Growth Industry ACM题答案 java版

题意: A biologist experimenting with DNA modification of bacteria has found a way to make bacterial colonies sensitive to the surrounding population density. By changing the DNA, he is able to "program" the bacteria to respond to the varying densi

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

zoj题目分类

饮水思源---zoj 转载自:http://bbs.sjtu.edu.cn/bbscon,board,ACMICPC,file,M.1084159773.A.html 注:所有不是太难的题都被归成了“简单题”,等到发现的时候已经太晚了,我太死脑筋 了……:( 有些题的程序我找不到了,555……:( SRbGa的题虽然都很经典……但是由于其中的大部分都是我看了oibh上的解题报告后做 的,所以就不写了…… 题目排列顺序没有规律……:( 按照个人感觉,最短路有的算做了DP,有的算做了图论. 有些比较

Day 4 @ RSA Conference Asia Pacific & Japan 2016

09.00 – 09.45 hrs Advanced Malware and the Cloud: The New Concept of 'Attack Fan-out' Krishna Narayanaswamy,Chief Scientist, Netskope The rapid rise in cloud adoption, of which organizations have underestimated the scope of by nearly 10x, has created

hdu 4185 Oil Skimming(二分匹配)

Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 883    Accepted Submission(s): 374 Problem Description Thanks to a certain "green" resources company, there is a new profitable

Constructing Roads In JGShining&#39;s Kingdom HDU - 1025

JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these cities are rich in resource (we call them rich cities) while the others are short of resource (we call them poor cities)