编程介的小学生 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条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算