HDU 4527 series of Xiao Ming stories

Source: Internet
Author: User

Question link:

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4527

Problem description James recently liked a game named ten drops of water.



The game is played in a 6*6 square, with a drop of water or no water on each grid. Water Drops are classified into four levels: 1 ~ 4. Initially, you have ten drops of water. By adding water to the Water Drop in the grid, the water drop will rise to 1 level. You can also put the water in an empty grid, which produces a level 1 water drop. When the water drop level is greater than 4, it will burst into four small water drops and splash in four directions. Each splash of small water drops will be integrated into other water drops, so that they can be upgraded or burst, and so on. The splash of small water drops does not interfere with each other, and the motion speed is equal (one second can move a grid distance ). Water Drops disappear after they burst.

Ideas:

Directly use BFS for simulation. Note that one unit of time and one unit of time must be taken during simulation. If two drops reach the other at the same time, then that drop + 2.

After this second, let's take a look at the water drops that are larger than 4 to be exploded, process them into the queue in four directions, and then proceed for one second.

# Include <cstdio> # include <cmath> # include <cstring> # include <iostream> # include <algorithm> using namespace STD; typedef long int64; const int INF = 0x3f3f3f; const int maxn = 10010; int m; int mat [8] [8]; int blast [8] [8]; // top, bottom, left, right const int dir [] [2] = {-}, {}, {0,-1}, {}; struct node {int X, Y; int CNT; int dir;} Q [500000]; void addque (int x, int y, int CNT, Int & Rear) {mat [x] [Y] = 0; for (INT I = 0; I <4; ++ I) {int dx = x + dir [I] [0]; int DY = Y + dir [I] [1]; if (dx> = 1 & DX <= 6 & dy> = 1 & dy <= 6) {q [rear]. X = DX; Q [rear]. y = Dy; Q [rear]. CNT = CNT; Q [rear ++]. dir = I ;}} void BFS (INT X, int y) {int front = 0, rear = 0; addque (X, Y, 0, rear ); int cur = 0; // current second while (front <rear) {While (front <rear & Q [Front]. CNT = cur) {// node & t = Q [Front ++]; If (MAT [T. x] [T. y]) {++ mat [T. x] [T. y];} else {node & Now = Q [rear]; now. X = T. X + dir [T. dir] [0]; now. y = T. Y + dir [T. dir] [1]; now. CNT = T. CNT + 1; now. dir = T. dir; If (now. x> = 1 & now. x <= 6 & now. y> = 1 & now. Y <= 6) ++ rear ;}}for (INT I = 1; I <= 6; ++ I) {for (Int J = 1; j <= 6; ++ J) if (MAT [I] [J]> 4) {addque (I, j, cur + 1, rear) ;}++ cur ;}} int main () {int X, Y; while (~ Scanf ("% d", & mat [1] [1]) {for (INT I = 1; I <= 6; ++ I) {for (Int J = (I = 1? 2: 1); j <= 6; ++ J) {scanf ("% d", & mat [I] [J]) ;}} scanf ("% d ", & M); For (INT I = 0; I <m; ++ I) {scanf ("% d", & X, & Y ); if (++ mat [x] [Y]> 4) {BFS (x, y) ;}} for (INT I = 1; I <= 6; ++ I) {for (Int J = 1; j <= 6; ++ J) if (J! = 1) printf ("% d", mat [I] [J]); else printf ("% d", mat [I] [J]); putchar ('\ n');} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.