admin 管理员组文章数量: 1184232
模拟
XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1550 Accepted Submission(s): 516
Problem Description
XYZ is playing an interesting game called “drops”. It is played on a r∗c grid. Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property “size”. The waterdrop cracks when its size is larger than 4, and produces 4 small drops moving towards 4 different directions (up, down, left and right).
In every second, every small drop moves to the next cell of its direction. It is possible that multiple small drops can be at same cell, and they won’t collide. Then for each cell occupied by a waterdrop, the waterdrop’s size increases by the number of the small drops in this cell, and these small drops disappears.
You are given a game and a position (x, y), before the first second there is a waterdrop cracking at position (x, y). XYZ wants to know each waterdrop’s status after T seconds, can you help him?
1≤r≤100, 1≤c≤100, 1≤n≤100, 1≤T≤10000
Input
The first line contains four integers r, c, n and T. n stands for the numbers of waterdrops at the beginning.
Each line of the following n lines contains three integers xi, yi, sizei, meaning that the i-th waterdrop is at position (xi, yi) and its size is sizei. (1≤sizei≤4)
The next line contains two integers x, y.
It is guaranteed that all the positions in the input are distinct.
Multiple test cases (about 100 cases), please read until EOF (End Of File).
Output
n lines. Each line contains two integers Ai, Bi:
If the i-th waterdrop cracks in T seconds, Ai=0, Bi= the time when it cracked.
If the i-th waterdrop doesn’t crack in T seconds, Ai=1, Bi= its size after T seconds.
Sample Input
4 4 5 10
2 1 4
2 3 3
2 4 4
3 1 2
4 3 4
4 4
Sample Output
0 5
0 3
0 2
1 3
0 1
模拟大小水滴。
//
// main.cpp
// 150730-1010
//
// Created by 袁子涵 on 15/7/30.
// Copyright (c) 2015年 袁子涵. All rights reserved.
//#include <iostream>
#include <stdio.h>
#include <string.h>using namespace std;int x,y;
int r,c,n,T;
int map[110][110];
int book[110][110];typedef struct wt
{int x,y,direction;
}WT;typedef struct water
{WT ball[4];int x,y,size;int A,B;
}Water;Water wtr[110];int main(int argc, const char * argv[]) {int times;while (scanf("%d%d%d%d",&r,&c,&n,&T)!=EOF) {memset(map, 0, sizeof(map));memset(book, 0, sizeof(book));for (int i=1; i<=n; i++) {cin >> wtr[i].x >> wtr[i].y >> wtr[i].size;wtr[i].A=1;wtr[i].B=wtr[i].size;map[wtr[i].x][wtr[i].y]=wtr[i].size;book[wtr[i].x][wtr[i].y]=1;}cin >> x >>y;times=T;wtr[0].A=0;map[x][y]+=4;wtr[0].x=x;wtr[0].y=y;for (int i=0; i<4; i++) {wtr[0].ball[i].x=x;wtr[0].ball[i].y=y;wtr[0].ball[i].direction=i+1;}while (times--) {//
// for (int i=1; i<=r; i++) {
// for (int j=1; j<=c; j++) {
// cout << map[i][j];
// }
// cout << endl;
// }
// cout <<endl<<endl;//先看各个小水珠for (int i=0; i<=n; i++) {//当已经爆裂后if (wtr[i].A==0) {//四个小水珠for (int j=0; j<4; j++) {//如果小水珠还在if (wtr[i].ball[j].direction!=-1) {//相应的移动switch (wtr[i].ball[j].direction) {case 1:if (wtr[i].ball[j].x==1) {map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;wtr[i].ball[j].direction=-1;break;}map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;wtr[i].ball[j].x--;map[wtr[i].ball[j].x][wtr[i].ball[j].y]++;if (book[wtr[i].ball[j].x][wtr[i].ball[j].y]) {wtr[i].ball[j].direction=-1;}break;case 2:if (wtr[i].ball[j].x==r) {map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;wtr[i].ball[j].direction=-1;break;}map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;wtr[i].ball[j].x++;map[wtr[i].ball[j].x][wtr[i].ball[j].y]++;if (book[wtr[i].ball[j].x][wtr[i].ball[j].y]) {wtr[i].ball[j].direction=-1;}break;case 3:if (wtr[i].ball[j].y==1) {map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;wtr[i].ball[j].direction=-1;break;}map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;wtr[i].ball[j].y--;map[wtr[i].ball[j].x][wtr[i].ball[j].y]++;if (book[wtr[i].ball[j].x][wtr[i].ball[j].y]) {wtr[i].ball[j].direction=-1;}break;case 4:if (wtr[i].ball[j].y==c) {map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;wtr[i].ball[j].direction=-1;break;}map[wtr[i].ball[j].x][wtr[i].ball[j].y]--;wtr[i].ball[j].y++;map[wtr[i].ball[j].x][wtr[i].ball[j].y]++;if (book[wtr[i].ball[j].x][wtr[i].ball[j].y]) {wtr[i].ball[j].direction=-1;}break;default:break;}}}continue;}//水滴未爆裂时continue;}//判断是否有新的水珠爆裂for (int i=1; i<=n; i++) {//如果还没有爆裂if (wtr[i].A==1) {if (map[wtr[i].x][wtr[i].y]>4) {wtr[i].A=0;wtr[i].B=T-times;book[wtr[i].x][wtr[i].y]=0;map[wtr[i].x][wtr[i].y]=4;//clear1(wtr[i].x, wtr[i].y);//自身爆出小水珠for (int j=0; j<4; j++) {wtr[i].ball[j].x=wtr[i].x;wtr[i].ball[j].y=wtr[i].y;wtr[i].ball[j].direction=j+1;}}//如果小于4else if (map[wtr[i].x][wtr[i].y]<=4){wtr[i].B=map[wtr[i].x][wtr[i].y];wtr[i].size=map[wtr[i].x][wtr[i].y];//clear1(wtr[i].x, wtr[i].y);}}}}//读出数据,输出for (int i=1; i<=n; i++) {cout << wtr[i].A << " " << wtr[i].B << endl;}}return 0;
}
本文标签: 模拟
版权声明:本文标题:模拟 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1693622564a232986.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论