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 ...
随机推荐
- Spring事务管理 与 SpringAOP
1,Spring事务的核心接口 Spring事务管理的实现有许多细节,如果对整个接口框架有个大体了解会非常有利于我们理解事务,下面通过讲解Spring的事务接口来了解Spring实现事务的具体策略. ...
- hdu 1703
#include<stdio.h> #define N 11000 int a[N]; int main() { int i,n; a[1]=0;a[2]=5;a[3] ...
- js/jquery 判断支持touchstart
if ('ontouchstart' in document.documentElement) { //... }
- BA--冷源系统原理图解
- 洛谷—— P1262 间谍网络
https://www.luogu.org/problem/show?pid=1262 题目描述 由于外国间谍的大量渗入,国家安全正处于高度的危机之中.如果A间谍手中掌握着关于B间谍的犯罪证据,则称A ...
- Python+Django+SAE系列教程16-----cookie&session
本章我们来解说cookie和session ,这两个东西相信大家一定不陌生,概念就不多讲了,我们直接来看其使用方法,首先是cookie,我们在view中加入三个视图,一个是显示cookie的,一个是设 ...
- Redis命令-HyperLogLog
HyperLogLog数据结构简单介绍 能够看http://www.cnblogs.com/ysuzhaixuefei/p/4052110.html 博客,介绍的相对照较清晰. HyperLogLo ...
- CGContext含义
代码 含义 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 CGContextMoveToPoint 开始画线 CGContex ...
- Python·Jupyter Notebook各种使用方法记录
标签(空格分隔): Python 一 Jupyter NoteBook的安装 1 新版本Anaconda自带Jupyter 2 老版本Anacodna需自己安装Jupyter 二 更改Jupyter ...
- jqueryui slider
<!doctype html><html lang="en"><head> <meta charset="utf-8" ...