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

Re:大家帮忙看看啊,数据全过了,就是WA.........哪里错了????

Posted by willsmith at 2012-04-20 13:46:12 on Problem 1101
In Reply To:题目 Posted by:zjydhr at 2008-12-10 23:01:02
c++的:
#include<iostream>
#include<queue>
using namespace std;

bool array[100][100]={(false,false)};
int le[100][100] = {-1};

struct node{
	int x;
	int y;
	int level;
	int way;
};
queue<node> que;

int main(){
	int w,h,x,y,i = 1;
	while (cin>>w>>h && (w !=0 || h!=0)){
		for (int s=0;s<100;++s)
			for (int t=0;t<100;++t)
				array[s][t] = false;
		char temp;
		cin.sync();
		for (int s=1;s<=h;++s){
			for (int t= 1;t<=w;++t){
				temp = getchar();
				if (temp == 'X')
					array[s][t] = true;
			}
			if (s != h) getchar();
		}
		node root;
		int count = 0;
		cout<<"Board #"<<i++<<":"<<endl;
		while (cin>>root.x>>root.y>>x>>y && (root.x != 0 || root.y != 0 || x != 0 || y != 0)){
			for (int s=0;s<100;++s)
				for(int t = 0;t<100;++t)
					le[s][t] = -1;
			while (!que.empty()) que.pop();
			root.level = 0;
			le[root.y][root.x] = 0;
			root.way = -1;
			que.push(root);
			while (!que.empty()){
				if (que.front().x == x && que.front().y == y){
					if (le[y][x] == -1 || le[y][x] > que.front().level)
						le[y][x] = que.front().level;
					que.pop();
				}
				else {
					//if (le[que.front().y][que.front().x] != -1 && que.front().level > le[que.front().y][que.front().x]){
					//	que.pop();
					//	continue;
					//}
					node current;
					current.x = que.front().x;
					current.y = que.front().y; 
					current.level = que.front().level;
					current.way = que.front().way;
					que.pop();
					if (current.x<=w && ((current.x +1 == x && current.y == y)||array[current.y][current.x+1] == false)){
						int a = current.level;
						if (current.way != 0) ++a;
						if (le[current.y][current.x+1] == -1 ||a <= le[current.y][current.x+1]){
							node e;
							e.x = current.x+1;
							e.y = current.y;
							e.level = a;
							e.way = 0;
							le[current.y][current.x+1] = a;
							que.push(e);
						}
					}
					if (current.x - 1>=0 && ((current.x -1 == x && current.y == y)|| array[current.y][current.x-1] == false)){
						int a = current.level;
						if (current.way != 1) ++a;
						if (le[current.y][current.x-1] == -1 ||a <= le[current.y][current.x-1]){
							node e;
							e.x = current.x-1;
							e.y = current.y;
							e.level = a;
							e.way = 1;
							le[current.y][current.x-1] = a;
							que.push(e);
						}
					}
					if (current.y <= h  && ((current.y + 1 == y && current.x == x)||array[current.y+1][current.x] == false)){
						int a = current.level;
						if (current.way != 2) ++a;
						if (le[current.y+1][current.x] == -1 ||a <= le[current.y+1][current.x]){
							node e;
							e.x = current.x;
							e.y = current.y+1;
							e.level = a;
							e.way = 2;
							le[current.y+1][current.x] = a;
							que.push(e);
						}
					}
					if (current.y - 1 >= 0 && ((current.y - 1 == y && current.x == x)||array[current.y-1][current.x] == false)){
						int a = current.level;
						if (current.way != 3) ++a;
						if (le[current.y-1][current.x] == -1 ||a <= le[current.y-1][current.x]){
							node e;
							e.x = current.x;
							e.y = current.y-1;
							e.level = a;
							e.way = 3;
							le[current.y-1][current.x] = a;
							que.push(e);
						}
					}
				}
			}
			if (le[y][x] == -1) cout<<"Pair "<<++count<<": impossible."<<endl;
			else cout<<"Pair "<<++count<<": "<<le[y][x]<<" segments."<<endl;
		}
		cout<<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