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

本文涉及的产品
云原生内存数据库 Tair,内存型 2GB
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Redis 版,经济版 1GB 1个月
简介: 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
相关文章
|
2月前
|
人工智能 算法 ice
【2024美赛】D题(中英文):五大湖水资源问题Problem Problem D: Great Lakes Water Problem
【2024美赛】D题(中英文):五大湖水资源问题Problem Problem D: Great Lakes Water Problem
43 1
|
8月前
Leetcode 365. Water and Jug Problem
一句话理解题意:有容积为x和y升的俩水壶,能不能量出z升的水。 我刚开始看到这题,立马就想了下暴力搜索的可能性,但考虑了下数据大小,立马放弃这个暴力的想法,于是意识到肯定有比较简单的数学方法,其实我自己没想到,后来看还是看了别人的代码,很多博客都直接给出了解法, 但没介绍为什么能这么解。所以我决定解释下我自己的思路。
33 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
53 0
|
机器学习/深度学习 人工智能
The Preliminary Contest for ICPC China Nanchang National Invitational I题 Max answer
The Preliminary Contest for ICPC China Nanchang National Invitational I题 Max answer
78 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
73 0
LeetCode 365. Water and Jug Problem
有两个容量分别为 x升 和 y升 的水壶以及无限多的水。请判断能否通过使用这两个水壶,从而可以得到恰好 z升 的水?
66 0
LeetCode 365. Water and Jug Problem
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
84 0