UVa201

#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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值