[Home|Training|Problems|Contests|C Language] | [Login|Register] |
Problems Status Rank |
Problem 1281
Unhappy dots
Time Limit: 1000ms
Memory Limit: 65536kb Description
There are k dots living on an n × m grid. A dot is happy if and only if he has at least two neighbors. Otherwise, he’s lonely and thus unhappy. Two dots are neighbors means that the manhattan distance between them is not greater than 1. Given the locations of all dots, your task to count the number unhappy dots. Input
The input consists of multiple test cases. The first line of each test case contains three integers k, n and m, which are described above. Next k lines each contains two integers xi and yi, indicating the location of a dot. (1 ≤ k ≤ 105, 1 ≤ xi ≤ m ≤ 109, 1 ≤ yi ≤ n ≤ 109) A test case begins with “0 0 0” indicates the end of input. Output
For each test case, output “Case x: ” first, where x is the case number. Then output the number unhappy dots. Sample Input
2 2 2 1 1 1 2 4 2 2 1 1 1 2 2 1 2 2 5 2 2 1 1 1 1 1 2 2 1 2 2 0 0 0 Sample Output
Case 1: 2 Case 2: 0 Case 3: 0 |