日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

HDU-4527 小明系列故事——玩转十滴水 模拟

發(fā)布時間:2023/12/2 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU-4527 小明系列故事——玩转十滴水 模拟 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題意:就是平時玩的十滴水游戲,游戲者擁有一定的水滴,能夠滴在某些位置,如果一個點上的體積超過了4就會爆炸,向四周傳遞一個小水滴。該題就是要求模擬這個過程。

分析:這里有一個問題就是不能夠使用遞歸來處理這個過程,因為水滴擁有速度,如果是遞歸調用的話,那么可能本來應該同時到達某點的水滴變成不同時間到達了。處理該題使用了兩個隊列,分別模擬當前時刻,和下一時刻,每次從當前時刻取出所有的水滴,再視情況處理加入到下一時刻的隊列中。有個地方要注意就是同時到達某一點的水滴加上原來的水滴超過了5那么視作和5等效。

#include <cstdlib> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <queue> using namespace std;int mp[10][10]; int m; struct Node {int x, y, d;Node() {}Node(int _x, int _y, int _d) : x(_x), y(_y), d(_d) {} }; queue<Node>q[2];int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};bool judge(int x, int y) {if (x < 1 || x > 6 || y < 1 || y > 6) return false;else return true; }void go(int x, int y) {if (mp[x][y] < 4) {mp[x][y]++;return;}int cur = 0, nxt = 1, xx, yy;mp[x][y] = 0;for (int i = 0; i < 4; ++i) {xx = x+dir[i][0], yy = y+dir[i][1];if (judge(xx, yy)) {q[cur].push(Node(xx, yy, i));}}Node tmp;while (!q[cur].empty()) {while (!q[cur].empty()) {tmp = q[cur].front();q[cur].pop();if (mp[tmp.x][tmp.y] == 0) {if (judge(xx=tmp.x+dir[tmp.d][0], yy=tmp.y+dir[tmp.d][1])) {q[nxt].push(Node(xx, yy, tmp.d));}} else {mp[tmp.x][tmp.y]++;}}for (int i = 1; i <= 6; ++i) {for (int j = 1; j <= 6; ++j) {if (mp[i][j] >= 5) {mp[i][j] = 0;for (int k = 0; k < 4; ++k) {xx = i + dir[k][0], yy = j + dir[k][1];if (judge(xx, yy)) {q[nxt].push(Node(xx, yy, k));}}}}}swap(cur, nxt);} }void print() {for (int i = 1; i <= 6; ++i) {for (int j = 1; j <= 6; ++j) {printf(j == 6 ? "%d\n" : "%d ", mp[i][j]);}} }int main() {while (scanf("%d", &mp[1][1]) != EOF) {for (int i = 2; i <= 6; ++i) {scanf("%d", &mp[1][i]);}for (int i = 2; i <= 6; ++i) {for (int j = 1; j <= 6; ++j) {scanf("%d", &mp[i][j]);}}scanf("%d", &m);int x, y;while (m--) {scanf("%d %d", &x, &y);go(x, y);} print();puts("");}return 0; }

?

轉載于:https://www.cnblogs.com/Lyush/p/3413367.html

總結

以上是生活随笔為你收集整理的HDU-4527 小明系列故事——玩转十滴水 模拟的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。