CSU 1569Wet Tiles
来源:互联网 发布:微博域名修改 编辑:程序博客网 时间:2024/06/04 18:06
Alice owns a construction company in the town of Norainia, famous for its unusually dry weather. In fact, it only 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 are not very water resistant; once a tile becomes wet, it is ruined and must be replaced. This year, Alice plans to handle the rainy days more efficiently than in past years. She will hire extra contractors to dispatch as soon as the calls come in, so hopefully all leaks can be repaired as soon as possible. For each house call, Alice needs a program to help her determine how many replacement tiles a contractor team will need to bring to complete the job.
For a given house, square floor tiles are 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 are ruined. After the second minute, water will have spread to any tile that shares an edge with a previously wet tile. This 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 are always four outer walls surrounding the entire house. A house may also have a number of additional "inner" walls; each inner wall is comprised of a connected linear sequence of locations (which may or may not be connected to the outer walls or to each other).
As an example, Figure 1 shows water damage (in gray) that 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 75 tiles have been damaged and will need to be replaced. Figures 2 through 4 show other houses that correspond to the example inputs for this problem.
75 wet tiles
17 wet tiles
4 wet tiles
94 wet tiles
Each house is described beginning with a line having 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, 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, are 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 will be 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 two ends of the wall. Each wall replaces a linear sequence of adjoining tiles and is either axis-aligned or intersects both axes at a 45 degree angle. Diagonal walls are modeled as a sequence of cells that would just be touching corner to corner. If the two endpoints of a wall are the same, the wall just occupies the single cell at that location. Walls may intersect with each other, but no leak is over a wall.
There will be one or more houses in the data file and a line with a single integer -1 designates the end of the data set.
For each house, display the total number of tiles that are wet after T minutes.
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
7517494
简单的说,就是一个有n个起点的图,进行bfs,问t时刻能覆盖多少个点。
#include<cstdio> #include<cstring>#include<queue>#include<cstdio>#include<algorithm> using namespace std;const int N = 1e3 + 10;int n, m, T, L, W;int vis[N][N];int dp[N][N], x, y, X, Y;int dir[4][2] = { 0,1,0,-1,1,0,-1,0 };int main(){while (~scanf("%d%d%d%d%d", &n, &m, &T, &L, &W) && n != -1) {memset(vis, 0, sizeof vis);memset(dp, 0, sizeof dp);int ans = 0;queue<pair<int, int> > p;for (int i = 1; i <= L; i++) {scanf("%d%d", &x, &y);if (!dp[x][y]) {ans++;dp[x][y] = 1;p.push(make_pair(x, y));}}for (int i = 1; i <= W; i++) {scanf("%d%d%d%d", &x, &y, &X, &Y);vis[x][y] = vis[X][Y] = 1;if (x == X) {if (y == Y) continue;for (int j = y; j != Y; j += (Y - y) / abs(Y - y)) {vis[x][j] = 1;}} else if (y == Y) {for (int j = x; j != X; j += (X - x) / abs(X - x)) {vis[j][y] = 1;}} else {for (int j = x, k = y; j != X; ) {vis[j][k] = 1; j += (X - x) / abs(X - x);k += (Y - y) / abs(Y - y);}}}while (!p.empty()){pair<int, int> q = p.front(); p.pop();if (dp[q.first][q.second] == T) continue;for (int i = 0; i < 4; i++) {int X = q.first + dir[i][0];int Y = q.second + dir[i][1];if (X<1 || X>n || Y<1 || Y>m || vis[X][Y] || dp[X][Y]) continue;dp[X][Y] = dp[q.first][q.second] + 1; p.push(make_pair(X, Y)); ++ans;}}printf("%d\n", ans);}return 0;}
- CSU 1569Wet Tiles
- CSU 1569 Wet Tiles(水~~)
- 1569: Wet Tiles
- Wet Tiles CSU Contest2073 - 湖南多校对抗赛(2015.04.06) I
- csu1569: Wet Tiles
- csu1569: Wet Tiles
- CSU1569 Wet Tiles
- CSU1569-Wet Tiles
- CSU1569: Wet Tiles(BFS控制时间相同)
- CSU 1569
- tiles
- tiles
- tiles
- Tiles
- CSU
- CSU
- CSU
- CSU
- 2017多校2 1003Maximum Sequence
- HDU 3416 Marriage Match IV(最短路,网络流)
- Spring MVC 基础及入门
- 快速幂,矩阵快速幂(模板)
- nmcli 网卡链路绑定team
- CSU 1569Wet Tiles
- 最少拦截系统
- hdu 1757 A Simple Math Problem(矩阵快速幂基础题)
- HDU 4578 Transformation(线段树+做了4天的神题+详解)
- Ubuntu的Samba服务,实现Windows映射网络盘到Ubuntu
- python 关于协程的二三事
- linux服务器查看防火墙状态
- laravel资源路由
- mysql使用临时量排序