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

Author

Andrew Stankevich
 
解题:乱搞,主要是坐标的范围太大,所以用set存已经被占领了的点。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
const int maxn = ;
const int dir[][] = {-,,,,,-,,};
pii p[maxn];
set< pii > s;
int tot;
void solve(int x,int y,int v){
int a = + v*,k = a>>;
int tx = x - ;
int ty = y + k;
for(int i = ; i < k; ++i){
for(int j = ; j < +*i; ++j){
pii tmp = make_pair(tx+j,ty);
if(s.count(tmp) == ) continue;
s.insert(tmp);
p[tot++] = tmp;
}
--tx;
--ty;
}
tx = x - k;
ty = y;
for(int i = ; i < a; ++i){
pii tmp = make_pair(tx+i,ty);
if(s.count(tmp) == ) continue;
s.insert(tmp);
p[tot++] = tmp;
}
tx = x - k;
ty = y - ;
for(int i = ; i < k; ++i){
for(int j = ; j < a; ++j){
pii tmp = make_pair(tx+j,ty);
if(s.count(tmp) == ) continue;
s.insert(tmp);
p[tot++] = tmp;
}
a -= ;
tx++;
ty--;
}
}
bool iswhite(int x,int y){
pii tmp = make_pair(x,y);
return s.count(tmp) == ;
}
void go(int x,int y){
bool p1 = iswhite(x-,y+);
bool p2 = iswhite(x,y+);
bool p3 = iswhite(x+,y+);
bool p4 = iswhite(x-,y);
bool p5 = iswhite(x+,y);
bool p6 = iswhite(x-,y-);
bool p7 = iswhite(x,y-);
bool p8 = iswhite(x+,y-); if(p1 && p2 && p4) return;
if(p2 && p3 && p5) return;
if(p4 && p6 && p7) return;
if(p5 && p7 && p8) return; pii tmp = make_pair(x,y);
p[tot++] = tmp;
s.insert(tmp);
}
int main(){
int n,x,y,v;
while(scanf("%d",&n),n){
s.clear();
for(int i = tot = ; i < n; ++i){
scanf("%d %d %d",&x,&y,&v);
solve(x,y,v);
}
for(int i = ; i < tot; ++i){
for(int j = ; j < ; ++j){
int tx = p[i].first + dir[j][];
int ty = p[i].second + dir[j][];
if(iswhite(tx,ty)) go(tx,ty);
}
}
printf("%d\n",s.size());
}
return ;
}

ZJU 2605 Under Control的更多相关文章

  1. ZJU 2676 Network Wars

    Network Wars Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...

  2. 企业管理软件开发架构之七 Object Control设计与运用

    在做查询时,经常遇到一类需求.请看下面的SQL语句查询 SELECT * FROM Company WHERE CompanyCode='Kingston' AND Suspended='N' AND ...

  3. 文字处理控件TX Text Control的使用

    这几天一直在研究TX Text Control的使用,由于这方面的资料相对比较少,主要靠下载版本的案例代码进行研究,以及官方的一些博客案例进行学习,使用总结了一些心得,特将其总结出来,供大家分享学习. ...

  4. Sublime text 2/3 中 Package Control 的安装与使用方法

    Package Control 插件是一个方便 Sublime text 管理插件的插件,但因为 Sublime Text 3 更新了 Python 的函数,API不同了,导致基于 Python 开发 ...

  5. Java 性能分析工具 , 第 3 部分: Java Mission Control

    引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...

  6. Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details

    thinkphp 在Apache上配置启用伪静态,重启Apache1 restart 竟然失败了,报错 Job for httpd.service failed because the control ...

  7. Neural Pathways of Interaction Mediating the Central Control of Autonomic Bodily State 自主神经系统-大脑调节神经通路

    Figure above: Critchley H D, Harrison N A. Visceral influences on brain and behavior[J]. Neuron, 201 ...

  8. Ubuntu[1]安装Vesta Control Panel

    参考:http://www.5013.org/archives/819 1)登录 ssh ubuntu@139.199.9.173 ubuntu@139.199.9.173's password: 重 ...

  9. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade

    XMLHttpRequest cannot load http://10.164.153.37:8050/WebService/WebService.asmx/wsGetStreetData. Res ...

随机推荐

  1. POJ 1950

    直接DFS,因为实在没想到什么剪枝了... 注意一点是,10.11使用的是1011哦 #include <iostream> #include <cstdio> #includ ...

  2. cocos2d-x 3.2 之 2048 —— 第五篇

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  3. Effective JavaScript Item 22 使用arguments来创建接受可变參数列表的函数

    本系列作为Effective JavaScript的读书笔记. 在Item 21中,介绍了结合apply方法实现的可变參数列表函数average,它实际上仅仅声明了一个数组作为參数,可是利用apply ...

  4. C# First and FirstOrDefault 方法详解

    在工作中我们经常会遇到有关LINQ 的一些问题.这时我们就用到lambda 表达式. 下面是我在工作遇到的. First  and FirstOrDefault  这两方法.我今天把它记录一下. 需要 ...

  5. Docker+ELK搭建

    换了个运行环境,重新搭建一套公司本地内部的ELK,之前也搭过(可访问:https://yanganlin.com/31.html),最近做什么事情都想用Docker,这次也用Docker,还算顺利,没 ...

  6. 客户现场调试(连接oracle数据库)

    1.System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本 http://blog.csdn.net/yucaoye/article/details/ ...

  7. python中黏包现象

    #黏包:发送端发送数据,接收端不知道应如何去接收造成的一种数据混乱现象. #关于分包和黏包: #黏包:发送端发送两个字符串"hello"和"word",接收方却 ...

  8. C#6.0新增功能

    C# 6.0 版本包含许多可提高开发人员工作效率的功能. 此版本中的功能包括: 只读自动属性: 可以创建只能在构造函数中设置的只读自动属性. 自动属性初始值设定项: 可以编写初始化表达式来设置自动属性 ...

  9. UWP tips (与wp8.1的不同)

    一.异步调用之后,要更新UI时,代码如下 await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =&g ...

  10. JavaScript基础知识-正则表达式

    正则表达式 作用:定义一个特定的验证字符串内容规则的表达式 注:正则表达式并不是JavaScript独有的:JavaScript支持正则表达式 var a = { };  // 定义一个空对象     ...