UVa201

#define LOCAL0
#include <stdlib.h>
#include <stdio.h>
#include "iostream"
#include "sstream"
#include <string.h>
#include <cmath>
#define inf 0x3f3f3f3f
using namespace std;
//mp[i][j]存的是从第i个点到第j个点有没有路。1<=i,j<=n*n;
int mp[200][200];
int valid(int mlen, int pos, int len)
{
	int j=(pos-1)%mlen+1, i=(pos-1)/mlen+1;
	if(i+len>mlen||j+len>mlen) return 0;
	int tmp,x,y;
	for(	tmp=len,x=pos,y=pos+mlen*len;
			tmp&&mp[x][x+1]&&mp[y][y+1];
			--tmp,++x,++y	)
		;
	if(tmp) return 0;
	for(	tmp=len,y=x,x=pos;
			tmp&&mp[x][x+mlen]&&mp[y][y+mlen];
			--tmp,x+=mlen,y+=mlen	)
		;
	if(tmp) return 0;
	return 1;
}
int main()
{
    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    
    int pset=0;
    int n,m,i,j,sz;
    char ch;
    while(cin>>n&&n){
    	cin>>m;
    	memset(mp,0,sizeof(mp));
    	while(m--){
    		cin>>ch>>i>>j;
    		if(ch=='H'){
    			int pos=n*(i-1)+j;
    			mp[pos][pos+1]=1;
			}
    		else if(ch=='V'){
    			int pos=n*(j-1)+i;
    			mp[pos][pos+n]=1;
    		}
    	}
    	int arr[10]={0};
    	for(sz=1;sz<n;++sz){
	    	for(i=1;i<=n*n;++i){
	    		if(valid(n,i,sz)){
	    			arr[sz]++;
	    		}
	    	}
	    }
	    if(pset>0){
	    	printf("\n**********************************\n\n");
	    }
	    printf("Problem #%d\n", ++pset);
	    int flag=0;
	    printf("\n");
	    for(i=1;i<10;i++){
	    	if(arr[i]){
	    		printf("%d square (s) of size %d\n", arr[i],i);
	    		flag=1;
	    	}
	    }
	    if(!flag)
	    	printf("No completed squares can be found.\n");
    }

    return 0;
}
这是测试数据:
4
16
H 1 1
H 1 3
H 2 1
H 2 2
H 2 3
H 3 2
H 4 2
H 4 3
V 1 1
V 2 1
V 2 2
V 2 3
V 3 2
V 4 1
V 4 2
V 4 3
2
3
H 1 1
H 2 1
V 2 1
4
16
H 1 1
H 1 3
H 2 1
H 2 2
H 2 3
H 3 2
H 4 2
H 4 3
V 1 1
V 2 1
V 2 2
V 2 3
V 3 2
V 4 1
V 4 2
V 4 3
2
3
H 1 1
H 2 1
V 2 1
4
16
H 1 1
H 1 3
H 2 1
H 2 2
H 2 3
H 3 2
H 4 2
H 4 3
V 1 1
V 2 1
V 2 2
V 2 3
V 3 2
V 4 1
V 4 2
V 4 3
2
3
H 1 1
H 2 1
V 2 1


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值