ZJU 2605 Under Control
Under Control
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
#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的更多相关文章
- ZJU 2676 Network Wars
Network Wars Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...
- 企业管理软件开发架构之七 Object Control设计与运用
在做查询时,经常遇到一类需求.请看下面的SQL语句查询 SELECT * FROM Company WHERE CompanyCode='Kingston' AND Suspended='N' AND ...
- 文字处理控件TX Text Control的使用
这几天一直在研究TX Text Control的使用,由于这方面的资料相对比较少,主要靠下载版本的案例代码进行研究,以及官方的一些博客案例进行学习,使用总结了一些心得,特将其总结出来,供大家分享学习. ...
- Sublime text 2/3 中 Package Control 的安装与使用方法
Package Control 插件是一个方便 Sublime text 管理插件的插件,但因为 Sublime Text 3 更新了 Python 的函数,API不同了,导致基于 Python 开发 ...
- Java 性能分析工具 , 第 3 部分: Java Mission Control
引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...
- 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 ...
- 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 ...
- 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: 重 ...
- 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 ...
随机推荐
- 启动 Appium 自带模拟器
1.先在sclipse中新建并打开一个设备 2.启动appium 3.安装apk 打开cmd 并在sdk安装目录的tools文件夹下输入安装命令adb install xxx.apk(在这之前需要把 ...
- sw算法求最小割学习
http:// blog.sina.com.cn/s/blog_700906660100v7vb.html 转载:http://www.cnblogs.com/ylfdrib/archive/201 ...
- [Tailwind] Get started with Tailwindcss
In this lesson, we learn how to generate CSS utility classes from Tailwind's JavaScript config file. ...
- Struts文件下载具体解释
在做项目中上传下载肯定是少不了的,本博文对struts2的下载进行解释并附上部分代码 1.action类 public class FileDownLoadAction extends ActionS ...
- 第18题 Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- HTTP Error 500.19
HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related ...
- 利用CSS3中的clac()实现按照屏幕分辨率自适应宽度
1.简介 calc()看其外表像个函数.平时在制作页面的时候,总会碰到有的元素是100%的宽度(例如body元素).如果元素宽度为100%时,其自身不带其他盒模型属性设置还好,要是有别的,那将导致盒子 ...
- C语言中文件定位函数总结
C语言中文件定位函数主要是:fseek, ftell, fsetpos, fgetpos. 先来讲前两个函数,这是最基本的定位函数: fseek函数:能把文件指针移动到文件任何位置,其原型是:int ...
- jar文件配置冲突问题transformResourcesWithMergeJavaResForDebug
先看本人AS报错异常 Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > c ...
- struct和class两个关键字的区别
1. <C++ Primer> 用class和struct关键字定义类的唯一差别在于默认访问级别:默认情况下,struct的成员为public,而class的成员为private. 2. ...