Advertisement
J00ker

Untitled

Apr 2nd, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #define Nmax 1048577
  4.  
  5. using namespace std;
  6.  
  7. struct Coada
  8. {
  9. int q[Nmax],pr,ul;void Init(){pr = 0;ul = - 1;}int Empty(){if(pr <= ul) return 0;return 1;}void Push(int x){ul++;q[ul] = x;}void Pop(){if(!Empty()) pr++;}int Front(){return q[pr];}int Size(){return ul - pr + 1;}
  10. };\
  11.  
  12. int n, nrFinal, v[Nmax];
  13.  
  14. void Operatie(int &x, int k)
  15. {
  16. int i, p, z;
  17. for(p = k; p <= n; p = p + k)
  18. {
  19. z = (1 << (p-1)); /// x = 2 la puterea p-1
  20. x = x ^ z;
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. int i, doila_i, x, y;
  27. Coada c, op;
  28. c.Init(); op.Init();
  29.  
  30. ifstream fin("sir.in");
  31. fin >> n;
  32. nrFinal = 0;
  33. doila_i = 1;
  34. for(i = 0; i < n; i++)
  35. {
  36. fin >> x;
  37. if(x == 1)
  38. nrFinal += doila_i;
  39. doila_i *= 2;
  40. }
  41. fin.close();
  42.  
  43. ///--Initializarea cozii--
  44. c.Init();
  45. c.Push(0);
  46. v[0] = 1;
  47. op.Push(0);
  48. int gata = 0;
  49. while(!c.Empty() && !gata)
  50. {
  51. x = c.Front();
  52. c.Pop();
  53. for(i = 1; i <= n; i++)
  54. {
  55. y = x;
  56. Operatie(y, i);
  57. if(v[y] == 0)
  58. {
  59. c.Push(y);
  60. op.Push(i);
  61. v[y] == 1;
  62. }
  63. if(y == nrFinal) gata = 1;
  64. }
  65. }
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement