HDU 1051 A New Growth Industry

相同的代码,在zoj能ac,在hdu就runtime error 。。。

检查之后才发现,zoj中的数组开的太大了。。。

#include<stdio.h>
#include<string.h>
int main()
{
    int day,i,j,K,n;
    int D[22],a[22][22],b[22][22];
    scanf("%d",&n);
    while(n--){
        scanf("%d",&day);
        memset(a,0,sizeof(a));
        for(i=0;i<16;i++)  scanf("%d",&D[i]);
        for(i=0;i<20;i++)
            for(j=0;j<20;j++)
                 scanf("%d",&a[i][j]);
        while(day--){
            for(i=0;i<20;i++){
               for(j=0;j<20;j++){
                   K=a[i][j];
                   K+=i-1>=0?a[i-1][j]:0;
                   K+=i+1<20?a[i+1][j]:0;
                   K+=j-1>=0?a[i][j-1]:0;
                   K+=j+1<20?a[i][j+1]:0;
                   b[i][j]=D[K]+a[i][j];
                   if(b[i][j]>3)  b[i][j]=3;
                   if(b[i][j]<0)  b[i][j]=0;
               }
            }
            memcpy(a,b,sizeof(a));
        }
            for(i=0;i<20;i++){
               for(j=0;j<20;j++){
                   switch(b[i][j]){
                       case 0: printf("."); break;
                       case 1: printf("!"); break;
                       case 2: printf("X"); break;
                       case 3: printf("#"); break;       
                   }       
               }
               printf("\n");   
            }
        if(n)  printf("\n");
    }
    system("pause");
    return 0;   
}

你可能感兴趣的:(System)