Csu1569:wet Tiles (BFS control time Same)

Source: Internet
Author: User

1569:wet Tiles Time limit: Sec Memory Limit: MB
Submit: Solved: 34
[Submit] [Status] [Web Board] Description

Alice owns a construction company in the town of Norainia, famous for its unusually dry weather. In fact, it is rains a few days per year there. Because of this phenomenon, many residents of Norainia neglect to do roof repairs until leaks occur and ruin their floors. Every year, Alice receives a deluge of calls from residents who need the leaks fixed and floor tiles replaced. While exquisite in appearance, Norainia floor tiles is not very water resistant; Once a tile becomes wet, it's ruined and must be replaced. This year, Alice plans to handle the rainy days more efficiently than in past years. She'll hire extra contractors to dispatch as soon as the calls come in, so hopefully all leaks can be repaired as soon a s possible. For each house call, Alice needs a program-to-help she determine how many replacement tiles a contractor team would need to Bring to complete the job.

for a given house, square floor tiles is arranged in a rectangular grid. Leaks originate from one or more known source locations above specific floor tiles. After the first minute, the tiles immediately below the leaks is ruined. After the second minute, water'll has spread to any tiles that shares an edge with a previously wet tile. This is the pattern of spreading water continues for each additional minute. However, the walls of a house restrict the water; If a damaged area hits a wall, the water does not penetrate the wall. We assume there is always a four-outer walls surrounding the entire house. A house may also has a number of additional "inner" walls; Each inner wall is comprised of a connected linear sequence of locations (which could or may isn't connected to the outer W Alls or to all other).

As an example, figure 1 shows water damage (in gray) the would result from three initial leaks (each marked with a white Letter ' L ') after each of the first five minutes of time. Tiles labeled ' 2 ' become wet during the second minute, Tiles labeled ' 3 ' become wet during the third minute, and so forth. The black areas designate inner walls that restrict the flow of water. Note that after 5 minutes, a total of tiles has been damaged and would need to be replaced. Figures 2 through 4 show other houses, correspond to the example inputs for this problem.

Wet Tiles

Wet Tiles

4 Wet Tiles

94 Wet Tiles

Input

Described beginning with a line has five integral parameters:x y T L W parameters X and Y designate the Dimensions of the rectangular grid, with 1≤x≤1000 and 1≤y≤1000. The coordinate system is one-indexed and as shown in the earlier figures. Parameter T designates the number of minutes that pass before a team of contractors arrives at a house and stops the leaks , with 1≤t≤200000. The parameter L designates the number of leaks, with 1≤l≤100. Parameter W designates the number of inner walls in the house, 0≤w≤100.

the following 2L integers in the data set, on one or more lines, is distinct (x y) pairs that designate The locations of the L distinct leaks, such that 1≤x≤x and 1≤y≤y.

if W > 0, there'll be a 4W additional integers, on one or more lines, that describe the locations of The walls. For each such wall the four parameters (X1,y1), (X2,y2) describe the locations of the ends of the. Each wall replaces a linear sequence of adjoining tiles and are either axis-aligned or intersects both axes at a degree Angle. Diagonal Walls is modeled as a sequence of cells that would just is touching corner to corner. If the endpoints of a wall is the same, the wall just occupies the single cell at the. Walls may intersect with each of the other, but no leak are over a wall.

There would be one or more houses in the data file and a line with a single integer-1 designates the end of the data set.

Output

For each house, display the total number of tiles is wet after T minutes.

Sample Input
12 12 5 3 52 11 3 3 9 51 9 6 9 1 7 4 4 7 1 7 410 9 10 12 11 4 12 49 7 8 1 34 32 2 6 6 6 2 2 6 8 2 8 26 7 50 1 33 42 2 2 6 3 6 5 4 5 4 3 212 12 5 3 02 11 3 3 9 5-1
Sample Output
7517494
HINT

Source
#include <stdio.h> #include <string.h> #include <queue>using namespace std;const int N = 1005;struct locate{int x, y;};    int mapt[n][n],n,m,t,dir[4][2]={0,1,0,-1,1,0,-1,0};queue<locate>q[2];void BFS (int flag) {Locate Pre,now;        while (!q[flag].empty ()) {Pre=q[flag].front (); Q[flag].pop ();            for (int e=0;e<4;e++) {now.x=pre.x+dir[e][0];            NOW.Y=PRE.Y+DIR[E][1];                if (now.x>0&&now.x<=n&&now.y>0&&now.y<=m&&mapt[now.x][now.y]==0) {                Mapt[now.x][now.y]=1;            Q[!flag].push (now);    }}}}int Main () {int l,w;    Locate Now,pre;        while (scanf ("%d", &n) >0&&n!=-1) {scanf ("%d%d%d%d", &m,&t,&l,&w);        for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) mapt[i][j]=0;        while (!q[0].empty ()) Q[0].pop ();        while (!q[1].empty ()) Q[1].pop ();       while (l--) {scanf ("%d%d", &now.x,&now.y); Q[0].push (now);            } while (w--) {scanf ("%d%d%d%d", &pre.x,&pre.y,&now.x,&now.y);                if (now.x>pre.x) {int TT; tt=pre.x; pre.x=now.x;                Now.x=tt; Tt=pre.y; PRE.Y=NOW.Y;            Now.y=tt; } if (pre.x==now.x) {if (pre.y<now.y) {int TT=PR E.y; PRE.Y=NOW.Y;                Now.y=tt;                } while (PRE.Y&GT;=NOW.Y) {mapt[pre.x][pre.y--]=2;                    }} else if (PRE.Y==NOW.Y) {if (pre.x<now.x) { int tt=pre.x; pre.x=now.x;                Now.x=tt;                } while (pre.x>=now.x) {mapt[pre.x--][pre.y]=2; }} else if (Pre.x>=now.x&&pre.y<=now. Y) {while (now.x<=pre.x&&now.y>=pre.y) {Mapt[n                    ow.x][now.y]=2; now.y--;                now.x++;                }} else {while (NOW.X&LT;=PRE.X&AMP;&AMP;NOW.Y&LT;=PRE.Y)                    {mapt[pre.x][pre.y]=2; pre.y--;                pre.x--;        }}} int flag=0;            while (!q[flag].empty ()) {t--;            if (t==0) break; BFS (flag);        Flag=!flag;        } int ans=0; for (int j=m;j>=1;j--) {for (int i=1;i<=n;i++) {//printf ("%d", mapt[i][j                ]);            if (mapt[i][j]==1) ans++;        }//printf ("\ n");    } printf ("%d\n", ans); }}


Csu1569:wet Tiles (BFS control time Same)

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.