Advertisement
iamyeasin

Untitled

Mar 26th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define     sf      scanf
  3. #define     pf      printf
  4. #define     dbg     cout << "Debug" << endl;
  5.  
  6. using namespace std;
  7.  
  8. vector < int > adjList[1024];
  9. int T,M,steps,n=0,counter=0,flag=0;
  10.  
  11. void printGrid();
  12. int front, rear,Trapped,Thesus;
  13. int L[1020],c=0;
  14. char lights[1024];
  15.  
  16. priority_queue<int, vector<int>, greater<int> >q;
  17. set < int > st;
  18. set<int>::iterator it;
  19.  
  20. bool isNomove(int cur ){
  21.     int flag = 0;
  22.     int sz = adjList[flag].size();
  23.  
  24.     for( int i=0; i<sz; i++ ){
  25.         int v = adjList[cur][i];
  26.         if( L[v] || v != T ){
  27.             return false;
  28.         }
  29.     }
  30.  
  31.     return true;
  32. }
  33.  
  34. void Solve( int M, int T ) {
  35.     st.insert( M );
  36.     int cn =0 ,nomove = 0;
  37.  
  38.     while( !st.empty() ){
  39.         M = (*st.begin());
  40.         st.erase(st.begin());
  41.         cn++;
  42.         cout << M << " " << T << endl;
  43.  
  44.         if( cn == steps ){
  45.             cn = 0;
  46.             L[M] = 1; lights[c++] = 'A'+ M;
  47.         }
  48.  
  49.         Trapped = M;
  50.  
  51.         int sz = adjList[M].size();
  52.  
  53.         for( int i=0; i<sz; i++ ){
  54.             int v = adjList[M][i];
  55.             if( v != T && L[v] == 0 ){
  56.                 st.insert( v );
  57.             }
  58.             if( isNomove( v ) ) {
  59.                 nomove = 1;
  60.                 break;
  61.             }
  62.  
  63.         }
  64.         if( nomove )break;
  65.         T = M;
  66.     }
  67. }
  68.  
  69. void clr(){
  70.  
  71.     for( int i=0; i<1050; i++ ){
  72.         adjList[i].clear();
  73.     }
  74.     Trapped = Thesus = flag = c=  0;
  75.     for( int i=0; i<1024; i++ ) {
  76.         L[i] = 0;
  77.         lights[i] = '\0';
  78.     }
  79.         st.clear();
  80.  
  81. }
  82.  
  83.  
  84. int main(){
  85.     #ifndef ONLINE_JUDGE
  86.         freopen("in.txt","rt",stdin);
  87.         //freopen("out.txt","wt",stdout);
  88.     #endif
  89.  
  90.     char str[1024];
  91.     front = rear = 0;
  92.     clr();
  93.  
  94.     while ( sf( "%s", str) , str[0] != '#' ) {
  95.  
  96.             counter = flag = n = 0 ;
  97.             scanf(" %c %c %d",&M,&T,&steps );
  98. //            cout << M << " " << T << " " << steps << endl;
  99.             n = 0;
  100.             char *pch,*st;
  101.             int x,y;
  102.             pch = strtok ( str, " :.");
  103.  
  104.             while ( pch != NULL ){
  105.                 x = pch[0] - 'A';n++;
  106.                 pch = strtok( NULL, ";.");
  107.  
  108.                 if( pch != NULL ){
  109.                     for( int i=0; pch[i]; i++ ){
  110.                         y = pch[i] - 'A';
  111.                         adjList[x].push_back(y);
  112.                     }
  113.                 }
  114.  
  115.               pch = strtok( NULL, " :;.");
  116.             }
  117. //            printGrid();
  118.             pch = NULL;
  119.  
  120.             Solve( M-'A' , T-'A' );
  121.             for( int i=0; i<c; i++ ){
  122.                 if(lights[i] != ('A' + Trapped))printf("%c ",lights[i]);
  123.             }
  124.             printf("/%c\n",Trapped +'A');
  125.  
  126.  
  127.             clr();
  128.             memset (str,'\0',sizeof str ) ;
  129.  
  130.     }
  131.  
  132.  
  133.  
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement