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

是不是一个门最多只打开一次

Posted by first at 2003-12-21 20:47:00 on Problem 1415
In Reply To:怎么老wa 不是很难的阿 Posted by:first at 2003-12-21 19:03:42
> 我用vector实现的
> 就是每当进入一个房间后
> 这个屋子房门数和来源房间减一~
> 对一个新房间 或者 负数 他的来源房间就是前面第一个房门数大于0的房间。
> 
> #include <iostream>
> #include <vector>
> #include <algorithm>
> using namespace std;
> struct room
> {
> 	short doors;
> 	short id;
> 	short dist;
> };
> void main()
> {
> 	int N,i,j,k;
> 	cin>>N;
> 	room temp;
> 	while(N--)
> 	{ 
>         int seq=0;
> 		vector <room> maze;
> 		vector <short> adj[100];
> 		while(cin>>temp.doors&&temp.doors)
> 		{
> 			if(temp.doors>0)
> 			{  
> 				temp.id=seq;
>                 seq++;
> 			}
> 			maze.push_back(temp);
> 		}
> 		maze[0].dist=0;
> 		for(i=1;i<maze.size();i++)
> 		{		 
> 			for(j=i-1;j>=0;j--)
> 			   if(maze[j].doors>0)
> 					break;
> 				if(maze[i].doors>0)
> 				{
> 					adj[maze[j].id].push_back(maze[i].id+1);
> 					adj[maze[i].id].push_back(maze[j].id+1);
> 					maze[i].dist=maze[j].dist+1;
> 					maze[i].doors--;
> 				}
> 				else if(maze[i].doors<0)
> 				{
> 				    int back=maze[j].dist+maze[i].doors;
> 					for(k=0;k<maze.size();k++)
> 						if(maze[k].dist==back)
> 						{
> 							adj[maze[j].id].push_back(maze[k].id+1);
> 							adj[maze[k].id].push_back(maze[j].id+1);
> 							maze[k].doors--;
> 							break;
> 						}
> 				}
> 		     maze[j].doors--;
> 		}
> 		for(i=0;i<seq;i++)
> 		{
> 			sort(adj[i].begin(),adj[i].end());
> 			cout<<i+1<<" ";
> 			for(j=0;j<adj[i].size();j++)
> 				cout<<adj[i][j]<<" ";
> 			cout<<endl;
> 		}
> 		
> 	}
> }
> 
> 
> 
> 

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