zoj 1051 A New Growth Industry

zoj  这个就是一个傻逼题目。题目都根本没法看懂。看了人家的解题报告才弄懂什么意思。就是每个元素上下左右四边元素加上这个元素 , 这五个元素和在D数组里找对应码。然后这个对应码再加上当前位置元素判断是否大于3 或着小于0,大于3 取3 ,小于0取0。那么这个结果就是一天后每个块的种群密度。


/*=============================================================================
#
#      Author: liangshu - cbam 
#
#      QQ : 756029571 
#
#      School : 哈尔滨理工大学 
#
#      Last modified: 2015-11-05 21:34
#
#     Filename: A.cpp
#
#     Description: 
#        The people who are crazy enough to think they can change the world, are the ones who do ! 
=============================================================================*/
#

#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
int main()
{
    int t, n;
    int d[40], dic[22][22], cnt[22][22];
    while(cin>>t){
        while(t--){
            int day;cin>>day;
            for(int i =0; i < 16; i++){
                cin>>d[i];
            }
            memset(cnt, 0, sizeof(cnt));
            for(int i = 1; i <= 20; i++){
                for(int j = 1; j <= 20; j++){
                    cin>>cnt[i][j];
                }
            }
            while(day--){
                    int i, j;
                for( i = 1; i <= 20; i++){
                    for(j = 1; j <= 20; j++){
                            int k = cnt[i][j];
                            int  t = k + cnt[i - 1][j] + cnt[i + 1][j] + cnt[i][j - 1] + cnt[i][j + 1];
                             dic[i][j] = t;


                    }
                }
                for(i = 1; i <= 20; i++){
                    for(j = 1; j <= 20; j++){
                        int v = (cnt[i][j] += d[dic[i][j]]);
                        if(v > 3){
                        cnt[i][j] = 3;
                        }
                        else if( v < 0){
                            cnt[i][j] = 0;
                        }
                    }
                }
            }
            for(int i = 1; i <= 20; i++){
                for(int j = 1; j <= 20; j++){
                    if(cnt[i][j] == 0){
                        cout<<".";
                    }
                    else if(cnt[i][j] == 1){
                        cout<<"!";
                    }
                    else if(cnt[i][j] == 2){
                        cout<<"X";
                    }
                    else if(cnt[i][j] == 3){
                        cout<<"#";
                    }
                }
                cout<<endl;
            }
            if(t){
                cout<<endl;
            }
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值