A New Growth Industry

From Progteam

Revision as of 23:26, 22 May 2008 by Mlc413 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


A New Growth Industry
Problem Number 1120
Sorter: mlc413
Source: Unknown
Link: http://acm.pku.edu.cn/JudgeOnline/problem?id=1120



A New Growth Industry is problem number 1120 on the Peking University ACM site.

A slight variation on the classic Game of Life problem.

Checkmark.jpg This problem has been solved by Mlc413.
import java.util.*;

public class Main{

    public static Scanner in;
 
    public static void main(String[] args){
        in=new Scanner(System.in);

        doStuff();
    }

    public static void doStuff(){
        int days=in.nextInt();
	int [] DNA = new int[16];
        for(int i=0; i < 16; i++){
	    DNA[i] = in.nextInt();
	}
	int[][] culture = new int[22][22];

	for(int j = 1; j <=20; j++){
	    for(int k =1; k<=20; k++){
		culture[j][k]=in.nextInt();
	    }
	}
	
	for(int l=0; l<days; l++){
	    culture = solve(culture, DNA);
	}
	print(culture);
    }

    public static int[][] solve(int[][] culture, int[] DNA){
	int[][] newC = new int[22][22];

	for(int i =1; i<=20; i++){
	    for(int j =1; j<=20; j++){
		int K = culture[i][j]+
		    culture[i-1][j]+
		    culture[i][j-1]+
		    culture[i][j+1]+
		    culture[i+1][j];

		newC[i][j] = culture[i][j] + DNA[K];
		if(newC[i][j] <=0){
		    newC[i][j] = 0;
		}
		else if(newC[i][j]>=3){
		    newC[i][j]=3;
		}
		
	    }
	}
	return newC;
    }

    public static void print(int[][] culture){
	for(int i =1; i<=20; i++){
	    for(int j =1; j<=20; j++){
		if(culture[i][j] <=0){
		    System.out.print('.');
		}
		else if(culture[i][j]>=3){
		    System.out.print('#');
		}
		else if(culture[i][j]==2){
		    System.out.print('X');
		}
		else{
		    System.out.print('!');
		}
	    }
	    System.out.println();
	}
    }
   
}

Personal tools