ZJU 2605 Under Control

Under Control

Time Limit: 2000ms

Memory Limit: 65536KB

This problem will be judged on ZJU. Original ID: 2605
64-bit integer IO format: %lld      Java class name: Main

In a game of Civilization III the area controlled by a city is defined by its culture level. The game proceeds on a rectangular grid. A city occupies one grid square. Each city has aculture level which is a non-negative integer number.

A city with a culture level 0 controls its own square and eight adjacent squares. A city with a culture level 1 additionally controls all squares that share a side with those squares (a total of 9 + 12 = 21 squares). Generally, if a city with a culture level i controls the set A of squares, a city with the same location and a culture level i + 1 would control all these squares and also squares that share a side with at least one square from A.

The picture on the left shows the sets of squares controlled by cities with culture levels of 0, 1 and 2.

The area controlled by the civilization is defined as follows. Consider the total area controlled by all its cities. The civilization area is the smallest set of squares, such that it contains all the squares controlled by some city, and its complement contains no hanging squares. A square x of a set B is called hanging if there is no 2 * 2 square in B that contains square x.

Calculate the total area controlled by a civilization, given the locations of all its cities on a map. You may consider that the map is infinite and that there are no other civilizations.

Input

The input consists of several test cases. In each case, the first line contains an integral number n - the number of the cities of a civilization (1 <= n <= 50). Next n lines describe cities. Each city is described with its integer coordinates (xi, yi) and its culture level ci. Coordinates do not exceed 109 by their absolute value, culture level does not exceed 10. The input ends up with a case where n = 0. Do not proceed this case.

Output

Output the total number of squares controlled by a civilization, each case in a single line.

Sample Input

2
0 0 1
4 -3 0
0

Sample Output

31

NOTE: The squares controlled by the civilization in the example are shown on the right picture. The square marked by a small circle is not controlled by any city, however it belongs to the area controlled by the civilization because otherwise it would be hanging.

Source

Andrew Stankevich‘s Contest #7

Author

Andrew Stankevich

解题:乱搞,主要是坐标的范围太大,所以用set存已经被占领了的点。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define INF 0x3f3f3f3f
15 #define pii pair<int,int>
16 using namespace std;
17 const int maxn = 100000;
18 const int dir[4][2] = {-1,0,0,1,0,-1,1,0};
19 pii p[maxn];
20 set< pii > s;
21 int tot;
22 void solve(int x,int y,int v){
23     int a = 3 + v*2,k = a>>1;
24     int tx = x - 1;
25     int ty = y + k;
26     for(int i = 0; i < k; ++i){
27         for(int j = 0; j < 3+2*i; ++j){
28             pii tmp = make_pair(tx+j,ty);
29             if(s.count(tmp) == 1) continue;
30             s.insert(tmp);
31             p[tot++] = tmp;
32         }
33         --tx;
34         --ty;
35     }
36     tx = x - k;
37     ty = y;
38     for(int i = 0; i < a; ++i){
39         pii tmp = make_pair(tx+i,ty);
40         if(s.count(tmp) == 1) continue;
41         s.insert(tmp);
42         p[tot++] = tmp;
43     }
44     tx =  x - k;
45     ty = y - 1;
46     for(int i = 0; i < k; ++i){
47         for(int j = 0; j < a; ++j){
48             pii tmp = make_pair(tx+j,ty);
49             if(s.count(tmp) == 1) continue;
50             s.insert(tmp);
51             p[tot++] = tmp;
52         }
53         a -= 2;
54         tx++;
55         ty--;
56     }
57 }
58 bool iswhite(int x,int y){
59     pii tmp = make_pair(x,y);
60     return s.count(tmp) == 0;
61 }
62 void go(int x,int y){
63     bool p1 = iswhite(x-1,y+1);
64     bool p2 = iswhite(x,y+1);
65     bool p3 = iswhite(x+1,y+1);
66     bool p4 = iswhite(x-1,y);
67     bool p5 = iswhite(x+1,y);
68     bool p6 = iswhite(x-1,y-1);
69     bool p7 = iswhite(x,y-1);
70     bool p8 = iswhite(x+1,y-1);
71
72     if(p1 && p2 && p4) return;
73     if(p2 && p3 && p5) return;
74     if(p4 && p6 && p7) return;
75     if(p5 && p7 && p8) return;
76
77     pii tmp = make_pair(x,y);
78     p[tot++] = tmp;
79     s.insert(tmp);
80 }
81 int main(){
82     int n,x,y,v;
83     while(scanf("%d",&n),n){
84         s.clear();
85         for(int i = tot = 0; i < n; ++i){
86             scanf("%d %d %d",&x,&y,&v);
87             solve(x,y,v);
88         }
89         for(int i = 0; i < tot; ++i){
90             for(int j = 0; j < 4; ++j){
91                 int tx = p[i].first + dir[j][0];
92                 int ty = p[i].second + dir[j][1];
93                 if(iswhite(tx,ty)) go(tx,ty);
94             }
95         }
96         printf("%d\n",s.size());
97     }
98     return 0;
99 }

时间: 2025-01-01 14:01:50

ZJU 2605 Under Control的相关文章

ZJU 2676 Network Wars

Network Wars Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 267664-bit integer IO format: %lld      Java class name: Main Special Judge Network of Byteland consists of n servers, connected by m optical cable

五:理解控件的运行机制(例:基于Control命名空间的简单控件)

一:先用最简短的话说点理论的1.asp.net中所有的标准控件都可以重写 2.和控件相关的命名空间有 System.Web.UI.Control是所有控件的基类只提供简单的呈现逻辑,不支持样式表 System.Web.UI.WebControls.WebControl继承自Control支持控件外观 System.Web.UI.WebControls.CompositeControl继承自WebControl类派生出多个控件合成的复合控件 3.控件树的实现原理首先Page类本身就是一个控件,它继

hdoj 4289 Control 【拆点 求最小割】

Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2295    Accepted Submission(s): 961 Problem Description You, the head of Department of Security, recently received a top-secret informati

Price Control V or S in Material Type (Price control in material master )

When is it useful to use the price control V or S in Material Master?  Do I have to follow the SAP standard setting in the material type for the following material types: - ROH (Raw materials) -> moving average price - HALB (Semifinished products) ->

ORA-01665 control file is not a standby control file

ORA-01665错误处理 问题描述: 在备库启动至mount状态时,报如下错误: ORA-01665: control file is not a standby control file 解决办法: 在主库备份一个控制文件 SQL> alter database create standby controlfile as '/home/oracle/bak.ctl'; 然后传到备库,用此控制文件启动数据库即可

centOS 7一个解决“network.service: control process exited, code=exited status=1”方法

今天早上2017-08-04,我打开虚拟机,使用远程工具xshell对虚拟机进行连接,我发现连接不上去,然后我ifconfig,发现找不到ens33了,就剩一个本地回环,看来是我的网络出现了问题,然后我查看我的网络状态,发现了如下情况: [[email protected] ~]# systemctl status network.service ● network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d

nginx提示Job for nginx.service failed because the control的问题

启动nginx时就报错!Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. 墙内外找了一圈找了一圈终于还是在墙外找到答案了.. 现在假设你是这样操作的:你修改了/etc/nginx/conf.d/default.con

sublime使用Package Control不能正常使用的解决办法

Sublime作为一款非常优秀的编辑器,套用中学语文课本里一篇讲梁启超的文章里形容梁启超的一句话,就是“短小精悍”.说它“短小”,是因为它的轻量级:说它“精悍”,则得益于它那包罗万象以适用于任何开发环境的插件功能.而插件的使用,则涉及到一个叫做Package Control的东西. Package Control是一个为了方便管理插件的插件,通过它可以快捷方便的安装和卸载插件. 但很多朋友在第一次使用Package Control时会遇到一个问题,就是: Package Control:Ther

Concurrent control in SQLite

This document describes the technologies to concurrent access to a SQLite database. There are also some code analysis to reveal the low level implementations. Multi-process See the official FAQ Can multiple applications or multiple instances of the s