#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<time.h>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
using namespace std;
const int INF = 0x3f3f3f3f;
using namespace std;
int table[1000][1000];
int cnt[15];
int main()
{
int n, m;
int cas = 1;
while (cin >> n >> m)
{
memset(cnt, 0, sizeof(cnt));
memset(table, 0, sizeof(table));
while (m--)
{
char temp;
cin >> temp;
int a, b;
cin >> a >> b;
if (temp == 'H')
{
table[(a - 1) * n + b][(a - 1) * n + b + 1] = 1;
table[(a - 1) * n + b + 1][(a - 1) * n + b] = 1;
}
else
{
table[(b - 1) * n + a][b *n + a] = 1;
table[b * n + a][(b - 1) *n + a] = 1;
}
}
for (int i = 1;i <= n*n;i++)
{
for (int k = 1;k<n;k++)
{
int sum = 0;
int len = 1;
int temp = i;
while (len <= k&&temp + n <= n*n)
{
sum += table[temp][temp + n];
temp += n;
len++;
}
len = 1;
while (len <= k&&temp + 1 <= n*n)
{
sum += table[temp][temp + 1];
temp += 1;
len++;
}
len = 1;
while (len <= k&&temp - n >= 1)
{
sum += table[temp][temp - n];
temp -= n;
len++;
}
len = 1;
while (len <= k&&temp - 1 >= 1)
{
sum += table[temp][temp - 1];
temp -= 1;
len++;
}
if (sum == k * 4)
cnt[k]++;
}
}
int flag = 0;
for (int i = 1;i<n;i++)
{
if (cnt[i] != 0)
{
flag = 1;
break;
}
}
if (cas != 1)
printf("\n**********************************\n\n");
printf("Problem #%d\n\n", cas++);
if (flag)
{
for (int i = 1;i<n;i++)
{
if (cnt[i] != 0)
cout << cnt[i] << " square (s) of size " << i << endl;
}
}
else
{
printf("No completed squares can be found.\n");
}
}
return 0;
}
UVa201
最新推荐文章于 2019-03-31 09:58:01 发布