Posted on 2009-06-04 14:30
superman 阅读(245)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 int min(int a, int b, int c)
6 {
7 return min(a, min(b, c));
8 }
9
10 int n;
11 int f[255][255];
12 bool map[255][255];
13
14 int main()
15 {
16 freopen("range.in", "r", stdin);
17 freopen("range.out", "w", stdout);
18
19 cin >> n;
20 for (int i = 0; i < n; i++)
21 for (int j = 0; j < n; j++)
22 {
23 char c;
24 cin >> c;
25 map[i][j] = (c == '0' ? false : true);
26 }
27
28 for (int i = 0; i < n; i++)
29 for (int j = 0; j < n; j++)
30 if (map[i][j])
31 {
32 f[i][j] = 1;
33
34 int t = 0;
35 if (i - 1 >= 0 && map[i - 1][j] &&
36 j - 1 >= 0 && map[i][j - 1] && map[i - 1][j - 1])
37 t = min(f[i - 1][j], f[i][j - 1], f[i - 1][j - 1]);
38
39 f[i][j] >?= t + 1;
40 }
41
42 int cnt[255] = { 0 };
43 for (int i = 0; i < n; i++)
44 for (int j = 0; j < n; j++)
45 if (f[i][j] >= 2)
46 for (int k = 2; k <= f[i][j]; k++)
47 cnt[k]++;
48
49 for (int i = 2; i <= 250; i++)
50 if (cnt[i])
51 cout << i << ' ' << cnt[i] << endl;
52
53 return 0;
54 }
55