HDU 1057-a New Growth industry

Source: Internet
Author: User

A simple simulation.

Given the number of days N, given d[0]~d[15] given a 20*20 matrix.
Each lattice has a 0~3 number that indicates the number of bacteria.
Every day, each lattice will be added with d[k],k to indicate the sum of the bacteria in the lattice and the adjacent lattice (The matrix is counted as 0, the number of bacteria per cell must not exceed 3, not less than 0).
Ask about the bacterial condition of n days.

1#include <iostream>2#include <cstdio>3 using namespacestd;4 intT,n;5 intd[ -];6 intmap[ -][ -],tmp[ -][ -];7 Chararr[]={'.','!','X','#'};8 intMain ()9 {Tenscanf"%d",&t); One      while(t--) A     { -scanf"%d",&n); -          for(intI=0;i< -; i++) scanf ("%d",&d[i]); the          for(intI=0;i< -; i++) -              for(intj=0;j< -; j + +) -scanf"%d",&map[i][j]); -         intsum; +          while(n--) -         { +              for(intI=0;i< -; i++) A                  for(intj=0;j< -; j + +) tmp[i][j]=Map[i][j]; at              for(intI=0;i< -; i++) -                  for(intj=0;j< -; j + +) -                 { -sum=Tmp[i][j]; -                     if(i>0) sum+=tmp[i-1][j]; -                     if(i< +) sum+=tmp[i+1][j]; in                     if(j>0) sum+=tmp[i][j-1]; -                     if(j< +) sum+=tmp[i][j+1]; tomap[i][j]+=D[sum]; +map[i][j]= map[i][j]>3?3: map[i][j]; -map[i][j]= map[i][j]<0?0: map[i][j]; the                 } *         } $          for(intI=0;i< -; i++)Panax Notoginseng         { -              for(intj=0;j< -; j + +) thecout<<Arr[map[i][j]]; +cout<<Endl; A         } the         if(t) puts (""); +     } -}

HDU 1057-a New Growth industry

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.