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 ;
}

最新文章

  1. ZKW线段树
  2. 使用C#类向数据库添加数据的例子源码
  3. [BZOJ2599][Race][IOI2011]点分治
  4. LongListSelector with bindable SelectedItem
  5. [CareerCup] 3.5 Implement Queue using Two Stacks 使用两个栈来实现队列
  6. 关于MyEcplise中常见的问题和解决方案
  7. Vim 常用命令 一
  8. mysql 存储过程事务
  9. C++ Code_Slider
  10. [未完成]关于枚举(Enum)
  11. CM5(Cloudera Manager 5) + CDH5(Cloudera&#39;s Distribution Including Apache Hadoop 5)的安装详细文档
  12. 【转】android-support-v7-appcompat.jar 的安装及相关问题解决 --- 汇总整理
  13. hibernate关联关系映射详解
  14. java生成Json工具之JsonSimple的使用
  15. Shell脚本,自动化发布tomcat项目【转载】
  16. 小程序 wepy框架 + iview-weapp的用法
  17. 栈(stack)信息
  18. MySQL的binlog日志&lt;转&gt;
  19. centos安装Django之三:安装python
  20. java模式之一------代理模式

热门文章

  1. python 在爬虫中timeout设置超时有什么作用
  2. 6 Javascript:函数
  3. 经验总结21--抓取WEB数据,汇率,HtmlAgilityPack
  4. Oracle配置网络服务
  5. CF149D 区间dp
  6. Oracle 11g 学习3——表空间操作
  7. AngularJS 下拉列表demo
  8. Oracle多表连接效率,性能优化
  9. swift属性观察者机智
  10. EF Code First 使用(一)