HDU-1057,A New Growth Industry(理解题意)

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: HDU-1057,A New Growth Industry(理解题意)

Problem Description:

网络异常,图片无法展示
|

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 densities in their immediate neighborhood.


The culture dish is a square, divided into 400 smaller squares (20x20). Population in each small square is measured on a four point scale (from 0 to 3). The DNA information is represented as an array D, indexed from 0 to 15, of integer values and is interpreted as follows:


In any given culture dish square, let K be the sum of that square's density and the densities of the four squares immediately to the left, right, above and below that square (squares outside the dish are considered to have density 0). Then, by the next day, that dish square's density will change by D[K] (which may be a positive, negative, or zero value). The total density cannot, however, exceed 3 nor drop below 0.


Now, clearly, some DNA programs cause all the bacteria to die off (e.g., [-3, -3, …, -3]). Others result in immediate population explosions (e.g., [3,3,3, …, 3]), and others are just plain boring (e.g., [0, 0, … 0]). The biologist is interested in how some of the less obvious DNA programs might behave.


Write a program to simulate the culture growth, reading in the number of days to be simulated, the DNA rules, and the initial population densities of the dish.  


Input:


Input to this program consists of three parts:


1. The first line will contain a single integer denoting the number of days to be simulated.


2. The second line will contain the DNA rule D as 16 integer values, ordered from D[0] to D[15], separated from one another by one or more blanks. Each integer will be in the range -3…3, inclusive.


3. The remaining twenty lines of input will describe the initial population density in the culture dish. Each line describes one row of squares in the culture dish, and will contain 20 integers in the range 0…3, separated from one another by 1 or more blanks.  


Output:


The program will produce exactly 20 lines of output, describing the population densities in the culture dish at the end of the simulation. Each line represents a row of squares in the culture dish, and will consist of 20 characters, plus the usual end-of-line terminator.


Each character will represent the population density at a single dish square, as follows:


网络异常,图片无法展示
|

No other characters may appear in the output.


Sample Input:


1


2


0 1 1 1 2 1 0 -1 -1 -1 -2 -2 -3 -3 -3 -3


3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


Sample Output:


##!.................


#!..................


!...................


....................


....................


....................


....................


.........!..........


........!#!.........


.......!#X#!........


........!#!.........


.........!..........


....................


....................


....................


....................


....................


....................


....................


....................


题目翻译:


培养皿为正方形,分为400个较小的正方形(20x20)。每个小方块中的人口均以四点制(从0到3)进行度量。 DNA信息表示为从0到15的整数D数组D,其解释如下:


在任何给定的培养皿正方形中,令K为该正方形的密度与紧接在该正方形的左,右,上和下四个正方形的密度之和(培养皿外部的正方形被视为密度为0)。然后,到第二天,该菜方的密度将改变D [K](可以是正值,负值或零值)。但是,总密度不能超过3,也不能低于0。


现在,很明显,某些DNA程序会导致所有细菌死亡(例如[-3,-3,…,-3])。其他导致人口激增(例如[3,3,3,…,3]),而其他则只是无聊(例如[0,0,…0])。生物学家对一些不太明显的DNA程序如何表现很感兴趣。


编写一个模拟培养物生长的程序,读取要模拟的天数,DNA规则和培养皿的初始种群密度。


该程序的输入包括三个部分:


第一行将包含一个整数,该整数表示要模拟的天数。


2.第二行将包含DNA规则D,为16个整数值,从D [0]到D [15]排序,彼此隔开一个或多个空格。每个整数将在-3…3(含)范围内。


3.其余的20行输入将描述培养皿中的初始种群密度。每行描述培养皿中的一排正方形,将包含20个整数,范围为0…3,彼此之间用1个或多个空白隔开。


该程序将精确地产生20行输出,在模拟结束时描述培养皿中的种群密度。每行代表培养皿中的一行正方形,将由20个字符以及通常的行结束符组成。


每个字符将代表一个菜盘上的人口密度,如下所示:输出中不能出现其他字符。


程序代码:


#include<stdio.h>
#include<string.h>
int arr[22][22],temp[22][22],d[17];
char sign[]={'.','!','X','#'};
int main()
{
  int t,n,k;
  scanf("%d",&t);
  while(t--)
  {
    scanf("%d",&n);
    for(int i=0;i<16;i++)
      scanf("%d",&d[i]);
    for(int i=1;i<21;i++)
      for(int j=1;j<21;j++)
        scanf("%d",&arr[i][j]);
    while(n--)
    {
      for(int i=1;i<21;i++)
        for(int j=1;j<21;j++)
        {
          k=arr[i][j]+arr[i][j-1]+arr[i][j+1]+arr[i-1][j]+arr[i+1][j];
          temp[i][j]=arr[i][j]+d[k];
          if(temp[i][j]<0)
            temp[i][j]=0;
          else if(temp[i][j]>3)
            temp[i][j]=3;
        }
      for(int i=1;i<21;i++)
        for(int j=1;j<21;j++)
          arr[i][j]=temp[i][j];
    }
    for(int i=1;i<21;i++)
    {
      for(int j=1;j<21;j++)
        printf("%c",sign[arr[i][j]]);     
      printf("\n");
    }
    if(t)
      printf("\n");
  }
  return 0;
}


相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
C++
hackerrank challenges median
只能说这题我想多了,使用普通的插入排序完全可以解决这道题,在查找的时候用二分加快查找速度。 正确解题报告 这道题的关键在于,不能用int,因为两个int相加可能会越界!因为这个WA了好多遍。所以改用long long。 对double,使用math.h中的函数ceil(double)可以取整,根据ceil(v) == v的结果可以判断v是否是整数。
56 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
54 0
UVa11714 - Blind Sorting
UVa11714 - Blind Sorting
55 0
|
C++
【PAT甲级 - C++题解】1096 Consecutive Factors
【PAT甲级 - C++题解】1096 Consecutive Factors
83 0
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
75 0
|
机器学习/深度学习
The Preliminary Contest for ICPC China Nanchang National Invitational J题 Distance on the tree
The Preliminary Contest for ICPC China Nanchang National Invitational J题 Distance on the tree
96 0
|
人工智能
Educational Codeforces Round 98 (Rated for Div. 2)B-Toy Blocks
You are asked to watch your nephew who likes to play with toy blocks in a strange way. He has n boxes and the i-th box has ai blocks. His game consists of two steps: he chooses an arbitrary box i; he tries to move all blocks from the i-th box to other boxes.
266 0
HDU-1017,A Mathematical Curiosity
HDU-1017,A Mathematical Curiosity
【1096】Consecutive Factors (20 分)
【1096】Consecutive Factors (20 分) 【1096】Consecutive Factors (20 分)
132 0