Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
是不是一个门最多只打开一次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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator