【HDOJ】1057 A New Growth Industry

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   sp   for   on   div   

純粹的類比題目。

 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4  5 #define MAXN 20 6 #define MAXM 16 7  8 char tb[] = ".!X#"; 9 int D[MAXM];10 int map[2][MAXN+2][MAXN+1];11 int dir[4][2] = {12     {-1,0}, {1,0}, {0,1}, {0,-1}13 };14 15 int isInvalid(int x, int y) {16     return x<0 || x>=MAXN || y<0 || y>=MAXN;17 }18 19 int main() {20     int t, n;21     int i, j, k, p, r;22     int x, y;23     int sum;24 25 #ifndef ONLINE_JUDGE26     freopen("data.in", "r", stdin);27     freopen("data.out", "w", stdout);28 #endif29     memset(map , 0, sizeof(map));30     scanf("%d", &t);31     while (t--) {32         scanf("%d", &n);33         for (i=0; i<MAXM; ++i)34             scanf("%d", &D[i]);35         for (r=0, i=1; i<=MAXN; ++i) {36             for (j=1; j<=MAXN; ++j) {37                 scanf("%d", &map[r][i][j]);38             }39         }40         for (p=0; p<n; ++p, r=!r) {41             for (i=1; i<=MAXN; ++i) {42                 for (j=1; j<=MAXN; ++j) {43                     sum = map[r][i][j] + map[r][i+1][j] + map[r][i-1][j]+44                             map[r][i][j+1] + map[r][i][j-1];45                     map[!r][i][j] = map[r][i][j] + D[sum];46                     if (map[!r][i][j] > 3)47                         map[!r][i][j] = 3;48                     if (map[!r][i][j] < 0)49                         map[!r][i][j] = 0;50                 }51             }52         }53         for (i=1; i<=MAXN; ++i) {54             for (j=1; j<=MAXN; ++j) {55                 printf("%c", tb[map[r][i][j]]);56             }57             printf("\n");58         }59         if (t)60             printf("\n");61     }62 63     return 0;64 }

 

【HDOJ】1057 A New Growth Industry

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.