fork(2) download
  1. #include "cave.h"
  2. #include <vector>
  3. using namespace std;
  4.  
  5. #define MAXN 5003
  6.  
  7. static int N,S[MAXN],D[MAXN];
  8. static bool find[MAXN];
  9. static vector <int> sw;
  10.  
  11. int dfs(int s,int e,int org,int door)
  12. {
  13. if (s == e) return sw[s];
  14. int i,m=(s+e)>>1,k;
  15. for (i=s;i<=m;i++) S[sw[i]] ^= 1;
  16. k = tryCombination(S);
  17. if ((org==door) != (k==door)) return dfs(s,m,k,door);
  18. else return dfs(m+1,e,k,door);
  19. }
  20.  
  21. void exploreCave(int n)
  22. {
  23. int i,j,k;
  24. N = n;
  25. for (i=0;i<N;i++){
  26. sw.clear();
  27. for (j=0;j<N;j++) if (!find[j]) sw.push_back(j);
  28. n = sw.size();
  29. k = tryCombination(S);
  30. k = dfs(0,n-1,k,i);
  31. find[k] = 1; D[k] = i;
  32. n = tryCombination(S);
  33. if (n == i) S[k] ^= 1;
  34. }
  35. answer(S,D);
  36. }
  37.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty