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. Could not publish server configuration for Tomcat v7.0 Server at localhost. Multiple Contexts have a path of "/ezoutdoor".

    Could not publish server configuration for Tomcat v7.0 Server at localhost. Multiple Contexts have a ...

  2. yii rbac管理

    以下是Controller代码 <?php /** * Created by PhpStorm. * User: zhoukang * Date: 2017/6/11 * Time: 19:31 ...

  3. net--技术栈(大图)

  4. OpenFace Docker 使用简介

    在Docker中使用openface最大的问题是数据与主机的交互,下面我介绍几种方法来实现主机与Docker容器的数据交互. 1.第一种也是最方便的一种方法是在进入容器时使用-v参数将主机的目录挂载到 ...

  5. linux块设备的IO调度算法和回写机制

    ************************************************************************************** 參考: <Linux ...

  6. CF149D 区间dp

    http://codeforces.com/problemset/problem/149/D D. Coloring Brackets time limit per test 2 seconds me ...

  7. 造个简单的轮子倒是不难,但可用性健壮性高到qt这样全世界都在用,就几乎不可能了

    造个简单的轮子倒是不难,但可用性健壮性高到qt这样全世界都在用,就几乎不可能了比如自己写个事件循环实现信号槽,还真不难,我这边的架构里就这么搞了个仿osgi的事件总线嵌入式实时操作系统上能用的大型gu ...

  8. 道里云SDN云网络技术:使云能够“众筹”

     容器云来了! 容器云的网络规模将比虚拟机云的情况扩大10-100倍,容器云与虚拟机云互联需求也将使云网络管控复杂度成数倍增长.SDN业界迎来了空前挑战.本报告分享道里云公司SDN技术:怎样将云的 ...

  9. hdoj--1754--I Hate It(线段树)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. DBS-Oracle:表的连接查询

    ylbtech-DBS-Oracle:表的连接查询 链接查询是指基于两个或两个以上表或试图的查询.在实际应用中,查询单个表可能无法满足应用程序的实际需求(例如显示雇员的部门名称以及雇员名),在这种情况 ...