Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define sf scanf
- #define pf printf
- #define dbg cout << "Debug" << endl;
- using namespace std;
- vector < int > adjList[1024];
- int T,M,steps,n=0,counter=0,flag=0;
- void printGrid();
- int front, rear,Trapped,Thesus;
- int L[1020],c=0;
- char lights[1024];
- priority_queue<int, vector<int>, greater<int> >q;
- set < int > st;
- set<int>::iterator it;
- bool isNomove(int cur ){
- int flag = 0;
- int sz = adjList[flag].size();
- for( int i=0; i<sz; i++ ){
- int v = adjList[cur][i];
- if( L[v] || v != T ){
- return false;
- }
- }
- return true;
- }
- void Solve( int M, int T ) {
- st.insert( M );
- int cn =0 ,nomove = 0;
- while( !st.empty() ){
- M = (*st.begin());
- st.erase(st.begin());
- cn++;
- cout << M << " " << T << endl;
- if( cn == steps ){
- cn = 0;
- L[M] = 1; lights[c++] = 'A'+ M;
- }
- Trapped = M;
- int sz = adjList[M].size();
- for( int i=0; i<sz; i++ ){
- int v = adjList[M][i];
- if( v != T && L[v] == 0 ){
- st.insert( v );
- }
- if( isNomove( v ) ) {
- nomove = 1;
- break;
- }
- }
- if( nomove )break;
- T = M;
- }
- }
- void clr(){
- for( int i=0; i<1050; i++ ){
- adjList[i].clear();
- }
- Trapped = Thesus = flag = c= 0;
- for( int i=0; i<1024; i++ ) {
- L[i] = 0;
- lights[i] = '\0';
- }
- st.clear();
- }
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("in.txt","rt",stdin);
- //freopen("out.txt","wt",stdout);
- #endif
- char str[1024];
- front = rear = 0;
- clr();
- while ( sf( "%s", str) , str[0] != '#' ) {
- counter = flag = n = 0 ;
- scanf(" %c %c %d",&M,&T,&steps );
- // cout << M << " " << T << " " << steps << endl;
- n = 0;
- char *pch,*st;
- int x,y;
- pch = strtok ( str, " :.");
- while ( pch != NULL ){
- x = pch[0] - 'A';n++;
- pch = strtok( NULL, ";.");
- if( pch != NULL ){
- for( int i=0; pch[i]; i++ ){
- y = pch[i] - 'A';
- adjList[x].push_back(y);
- }
- }
- pch = strtok( NULL, " :;.");
- }
- // printGrid();
- pch = NULL;
- Solve( M-'A' , T-'A' );
- for( int i=0; i<c; i++ ){
- if(lights[i] != ('A' + Trapped))printf("%c ",lights[i]);
- }
- printf("/%c\n",Trapped +'A');
- clr();
- memset (str,'\0',sizeof str ) ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement