Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

注意特殊trick

Posted by Tachi_kanade at 2014-06-17 15:58:17 on Problem 1647
感谢这道题…无比的感谢

注意白后可以被白王阻挡

上代码
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 12 ;
int n;
int a[N][N];
bool vis[N][N];

int poswkx,poswky,posbkx,posbky;
int ansx[100],ansy[100];
int top;
int posx,posy;

void print()
{
	for(int i=0;i<=n+1;i++){
	for(int j=0;j<=n+1;j++)
		cout<<vis[i][j];
	cout<<endl;}cout<<endl;
}

inline int  Abs(int x)
{
	if(x>=0) return x;
	else return -x;
}

bool next(int x1,int y1,int x2,int y2)
{
	if(abs(x1-x2)<=1 && abs(y1-y2)<=1)
		return 1;
	else return 0;
}

bool check(int x,int y)
{
	if( !( posx==x || posy==y || (posx-posy==x-y) || (x+y==posx+posy) )  )
		return 0;
	if(next(x,y,posbkx,posbky) && !next(x,y,poswkx,poswky) )	
		return 0;
	if(x==poswky && y==poswkx) return 0;
	
	
	memset(vis,0,sizeof(vis));
	for(int i=0;i<=n+1;i++)
		vis[0][i]=vis[i][0]=vis[i][9]=vis[9][i]=1;
	
	int wx=poswky,wy=poswkx;
	
	vis[wx][wy]=vis[wx-1][wy-1]=vis[wx-1][wy]=vis[wx-1][wy+1]=vis[wx][wy-1]=vis[wx][wy+1]=vis[wx+1][wy+1]=vis[wx+1][wy]=vis[wx+1][wy-1]=1;

	for(int i=1;i<=n;i++)
		vis[y][i]=vis[i][x]=1;
	
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	{
		if(i-j==x-y) vis[j][i]=1;
		if(i+j==x+y) vis[j][i]=1;
	}

	wx=posbky,wy=posbkx;
	if(vis[wx][wy]==1 && vis[wx-1][wy-1]==1 && vis[wx-1][wy]==1 && vis[wx-1][wy+1]==1 && vis[wx][wy-1]==1 &&
	vis[wx][wy+1]==1 && vis[wx+1][wy+1]==1 && vis[wx+1][wy]==1 && vis[wx+1][wy-1]==1)
		return 1;
	else return 0;
}

int main()
{
	n=8;
	string s1,s2,s3;
	cin>>s1>>s2>>s3;// wK wQ Bk
	char c1=s1[0],c2=s1[1];
	a[c2-'0'][c1-'a'+1]=1;
	poswkx=c1-'a'+1,poswky=c2-'0';
	
	c1=s2[0],c2=s2[1];
	posx=c1-'a'+1,posy=c2-'0';
	
	c1=s3[0],c2=s3[1];
	a[c2-'0'][c1-'a'+1]=3;
	posbkx=c1-'a'+1,posbky=c2-'0';

	bool flag=0;
	int x=posx,y=posy;
	int tmp;
	
	while(x>0)
	{
		if(a[x][y]) break;
		if(check(x,y)) 
		{
			ansx[++top]=x,ansy[top]=y;
			flag=1;
		}
		x--;
	}
	
	x=posx,y=posy;
	while(x<=n)
	{
		if(a[x][y]) break;
		if(check(x,y)) 
		{
			ansx[++top]=x,ansy[top]=y;
			flag=1;
		}
		x++;
	}
	
	x=posx,y=posy;
	while(y>0)
	{
		if(a[x][y]) break;
		if(check(x,y)) 
		{
			ansx[++top]=x,ansy[top]=y;
			flag=1;
		}
		y--;
	}
	
	x=posx,y=posy;
	while(y<=n)
	{
		if(a[x][y]) break;
		if(check(x,y)) 
		{
			ansx[++top]=x,ansy[top]=y;
			flag=1;
		}
		y++;
	}
	
	x=posx,y=posy;
	while(x<=n && y<=n)
	{
		if(a[x][y]) break;
		if(check(x,y)) 
		{
			ansx[++top]=x,ansy[top]=y;
			flag=1;
		}
		x++,y++;
	}
	
	x=posx,y=posy;
	while(x>=1 && y>=1)
	{
		if(a[x][y]) break;
		if(check(x,y)) 
		{
			ansx[++top]=x,ansy[top]=y;
			flag=1;
		}
		x--,y--;
	}
	
	x=posx,y=posy;
	while(x<=n&&y>=1)
	{
		if(a[x][y]) break;
		if(check(x,y)) 
		{
			ansx[++top]=x,ansy[top]=y;
			flag=1;
		}
		x++,y--;
	}
	
	x=posx,y=posy;
	while(x>0 && y<=n )
	{
		if(a[x][y]) break;
		if(check(x,y)) 
		{
			ansx[++top]=x,ansy[top]=y;
			flag=1;
		}
		x--,y++;
	}	
	int ansxx=9,ansyy=9;
	for(int i=1;i<=top;i++)
		if(ansx[i]<ansxx || (ansx[i]==ansxx && ansy[i]<ansyy))
			ansxx=ansx[i],ansyy=ansy[i];
	if(flag)
	cout<<char(ansxx-1+'a')<<ansyy<<endl;
	
	if(!flag) cout<<"no"<<endl;
	
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator