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

大家提供的测试点都过了 为什么还是wa?

Posted by bxdd at 2016-05-24 12:30:06 on Problem 1324
#include<cstdio>
#include<queue>
#include<iostream>
#include<cstring>
#define maxn 21
using namespace std;
const int dx[]={0,-1,1,0,0};
const int dy[]={0,0,0,-1,1};
int n,m,l;
int k;
bool vis[21][21][16400];
struct point{
	int x[10],y[10];
	//int grap[maxn][maxn];(MLE)
	int h;
};
int grap[maxn][maxn];
int graping[maxn][maxn];
queue <point> p;
void cleanqueue(){
	while(!p.empty()){
		p.pop();
	}
	return;
}
bool find(point w4){
	int xt=w4.x[1];
	int yt=w4.y[1];
	int val=0;
	for(int i=2;i<=l;i++){
		int ax,ay;
		ax=w4.x[i]-w4.x[i-1];
		ay=w4.y[i]-w4.y[i-1];
		if(ax==1){
			val=val*4;
		}
		if(ay==1){
			val=val*4+1;
		}
		if(ax==-1){
			val=val*4+2;
		}
		if(ay==-1){
			val=val*4+3;
		}
	}
	if(vis[xt][yt][val]){
		return false;
	}
	else{
		vis[xt][yt][val]=true;
		return true;
	}
}
int main(){
	int t=0;
	while(1){
		t++;
		memset(vis,false,sizeof(vis));
		cin>>n>>m>>l;
		if(n==0&&m==0&&l==0) break;
		point w1;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++){
				grap[i][j]=graping[i][j]=0;
		}
		for(int i=1;i<=l;i++){
			cin>>w1.x[i]>>w1.y[i];
			//graping[w1.x[i]][w1.y[i]]=1;
		}
		cin>>k;
		for(int i=1;i<=k;i++){
			int x0,y0;
			cin>>x0>>y0;
			grap[x0][y0]=graping[x0][y0]=-1;
		}
		w1.h=0;
		p.push(w1);
		int ok=0;
		while(!p.empty()){
			if(ok) break;
			point w2;
			w2=p.front();
			p.pop();
			int x1,y1;
			for(int i=1;i<=4;i++){
				x1=w2.x[1]+dx[i];
				y1=w2.y[1]+dy[i];
				if(x1>=1&&x1<=n&&y1>=1&&y1<=m){
					for(int i=1;i<=l;i++){
						graping[w2.x[i]][w2.y[i]]=1;
					}
					if(graping[x1][y1]==0){
						point w3;
						//memcpy(w3.grap,w2.grap,sizeof(w2.grap));
						w3.x[1]=x1;
						w3.y[1]=y1;	
						w3.h=w2.h+1;
						//grap[x1][y1]=1;
						for(int i=l;i>=2;i--){
							w3.x[i]=w2.x[i-1];
							w3.y[i]=w2.y[i-1];
						}
						//grap[w2.x[l]][w2.y[l]]=0;
						if(find(w3)){
							p.push(w3);	
						}
					}
				if(graping[1][1]==1){
					ok=1;
					cout<<"Case "<<t<<": "<<w2.h<<endl;
					break;
				}
				memcpy(graping,grap,sizeof(grap));
				}
			}
		}
		if(!ok) cout<<"Case "<<t<<": "<<-1<<endl;
		cleanqueue();
	}
	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