sdut2415 Chess (山东第三届省赛)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100005
using namespace std;
struct node{
	int x,y;
	int p;
	int pos;
}x[N],y[N],x_y[N],xy[N],xxy[N],xyy[N],x_yy[N],xx_y[N];
int hited[N];
bool cmpxxy(node a,node b){
	if(b.x-a.x==(b.y-a.y)*2)
		return a.x<b.x;
	return (b.y-a.y)*2<b.x-a.x;
}
bool cmpxyy(node a,node b){
	if(b.y-a.y==(b.x-a.x)*2)
		return a.x<b.x;
	return b.y-a.y<(b.x-a.x)*2;
}
bool cmpxx_y(node a,node b){
	if(b.x-a.x==(a.y-b.y)*2)
		return a.x<b.x;
	return (a.y-b.y)*2<b.x-a.x;
}
bool cmpx_yy(node a,node b){
	if(a.y-b.y==(b.x-a.x)*2)
		return a.x<b.x;
	return a.y-b.y<(b.x-a.x)*2;
}
bool cmpxy(node a,node b){
	if(b.x-a.x==b.y-a.y)
		return a.x<b.x;
	return b.y-a.y<b.x-a.x;
}
bool cmpx_y(node a,node b){
	if(b.x-a.x==a.y-b.y)
		return a.x<b.x;
	return a.y-b.y<b.x-a.x;
}
bool cmpy(node a,node b){
	if(a.y==b.y)
		return a.x<b.x;
	return a.y<b.y;
}
bool cmpx(node a,node b){
	if(a.x==b.x)
		return a.y<b.y;
	return a.x<b.x;
}
int main(){
	int t,icase=1;
	scanf("%d",&t);
	int n;
	int xx,yy;
	char pp[3];
	while(t--){
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d%d%s",&xx,&yy,pp);
			x[i].x = y[i].x = x_y[i].x = xy[i].x = xxy[i].x = xyy[i].x = x_yy[i].x = xx_y[i].x = xx;
			x[i].y = y[i].y = x_y[i].y = xy[i].y = xxy[i].y = xyy[i].y = x_yy[i].y = xx_y[i].y = yy;
			x[i].p = y[i].p = x_y[i].p = xy[i].p = xxy[i].p = xyy[i].p = x_yy[i].p = xx_y[i].p = pp[0]-'A';
			x[i].pos = y[i].pos = x_y[i].pos = xy[i].pos = xxy[i].pos = xyy[i].pos = x_yy[i].pos = xx_y[i].pos = i;
		}
		sort(x,x+n,cmpx);
		sort(y,y+n,cmpy);
		sort(x_y,x_y+n,cmpx_y);
		sort(xy,xy+n,cmpxy);
		sort(xxy,xxy+n,cmpxxy);
		sort(xyy,xyy+n,cmpxyy);
		sort(x_yy,x_yy+n,cmpx_yy);
		sort(xx_y,xx_y+n,cmpxx_y);
		memset(hited,0,sizeof(hited));
		for(int i=0;i<n;i++){
			if(x[i].p==10||x[i].p==17||x[i].p==16){
				if(i>0){
					if(x[i-1].x==x[i].x){
						if(x[i].p==10){
							if(x[i-1].y+1==x[i].y)
								hited[x[i-1].pos]++;
						}
						else
							hited[x[i-1].pos]++;
					}
				}
				if(i<n-1){
					if(x[i].x==x[i+1].x){
						if(x[i].p==10){
							if(x[i].y+1==x[i+1].y)
								hited[x[i+1].pos]++;
						}
						else
							hited[x[i+1].pos]++;
					}
				}
			}
			if(y[i].p==10||y[i].p==17||y[i].p==16){
				if(i>0){
					if(y[i-1].y==y[i].y){
						if(y[i].p==10){
							if(y[i-1].x+1==y[i].x)
								hited[y[i-1].pos]++;
						}
						else
							hited[y[i-1].pos]++;
					}
				}
				if(i<n-1){
					if(y[i].y==y[i+1].y){
						if(y[i].p==10){
							if(y[i].x+1==y[i+1].x)
								hited[y[i+1].pos]++;
						}
						else
							hited[y[i+1].pos]++;
					}
				}
			}
			if(x_y[i].p==10||x_y[i].p==1||x_y[i].p==16){
				if(i>0){
					if(x_y[i].x-x_y[i-1].x==x_y[i-1].y-x_y[i].y){
						if(x_y[i].p==10){
							if(x_y[i-1].x+1==x_y[i].x)
								hited[x_y[i-1].pos]++;
						}
						else
							hited[x_y[i-1].pos]++;
					}
				}
				if(i<n-1){
					if(x_y[i+1].x-x_y[i].x==x_y[i].y-x_y[i+1].y){
						if(x_y[i].p==10){
							if(x_y[i].x+1==x_y[i+1].x)
								hited[x_y[i+1].pos]++;
						}
						else
							hited[x_y[i+1].pos]++;
					}
				}
			}
			if(xy[i].p==10||xy[i].p==1||xy[i].p==16){
				if(i>0){
					if(xy[i].x-xy[i-1].x==xy[i].y-xy[i-1].y){
						if(xy[i].p==10){
							if(xy[i-1].x+1==xy[i].x)
								hited[xy[i-1].pos]++;
						}
						else
							hited[xy[i-1].pos]++;
					}
				}
				if(i<n-1){
					if(xy[i+1].x-xy[i].x==xy[i+1].y-xy[i].y){
						if(xy[i].p==10){
							if(xy[i].x+1==xy[i+1].x)
								hited[xy[i+1].pos]++;
						}
						else
							hited[xy[i+1].pos]++;
					}
				}
			}
			if(x_yy[i].p==13){
				if(i>0){
					if((x_yy[i].x-x_yy[i-1].x)*2==x_yy[i-1].y-x_yy[i].y)
						if(x_yy[i].x==x_yy[i-1].x+1)
							hited[x_yy[i-1].pos]++;
				}
				if(i<n-1){
					if((x_yy[i+1].x-x_yy[i].x)*2==x_yy[i].y-x_yy[i+1].y)
						if(x_yy[i+1].x==x_yy[i].x+1)
							hited[x_yy[i+1].pos]++;
				}
			}
			if(xx_y[i].p==13){
				if(i>0){
					if(xx_y[i].x-xx_y[i-1].x==(xx_y[i-1].y-xx_y[i].y)*2)
						if(xx_y[i-1].y==xx_y[i].y+1)
							hited[xx_y[i-1].pos]++;
				}
				if(i<n-1){
					if(xx_y[i+1].x-xx_y[i].x==(xx_y[i].y-xx_y[i+1].y)*2)
						if(xx_y[i].y==xx_y[i+1].y+1)
							hited[xx_y[i+1].pos]++;
				}
			}
			if(xxy[i].p==13){
				if(i>0){
					if(xxy[i].x-xxy[i-1].x==(xxy[i].y-xxy[i-1].y)*2)
						if(xxy[i-1].y+1==xxy[i].y)
							hited[xxy[i-1].pos]++;
				}
				if(i<n-1){
					if(xxy[i+1].x-xxy[i].x==(xxy[i+1].y-xxy[i].y)*2)
						if(xxy[i].y+1==xxy[i+1].y)
							hited[xxy[i+1].pos]++;
				}
			}
			if(xyy[i].p==13){
				if(i>0){
					if((xyy[i].x-xyy[i-1].x)*2==xyy[i].y-xyy[i-1].y)
						if(xyy[i-1].x+1==xyy[i].x)
							hited[xyy[i-1].pos]++;
				}
				if(i<n-1){
					if((xyy[i+1].x-xyy[i].x)*2==xyy[i+1].y-xyy[i].y)
						if(xyy[i].x+1==xyy[i+1].x)
							hited[xyy[i+1].pos]++;
				}
			}
		}
		int ans[18]={0};
		for(int i=0;i<n;i++)
			ans[hited[i]]++;
		printf("Case %d:\n",icase++);
		for(int i=0;i<16;i++)
			printf("%d ",ans[i]);
		printf("%d\n",ans[16]);
	}
	return 0;
} 



/**************************************
	Problem id	: SDUT OJ 2415 
	Result		: Accepted 
	Take Memory	: 13372K 
	Take Time	: 420MS 
	Submit Time	: 2014-05-02 00:38:02  
**************************************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值