编程介的小学生 2017-08-22 09:04 采纳率: 20.5%
浏览 779
已采纳

Under Control

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 a culture 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

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度