Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. #include<vector>
  4. #include<stack>
  5. #include<ctime>
  6.  
  7. using namespace std;
  8. const int maxn=60;
  9. bool used[maxn];
  10. vector<vector<int> > g;
  11. typedef pair<long long,int> res;
  12. stack<long long> vasya;
  13. long long time_trigger;
  14. const long long max_trig = 2;
  15. const int max_back_track_capacity = 1000060;
  16. int solution[max_back_track_capacity];
  17. int nexter[max_back_track_capacity];
  18. int current_arr_size;
  19. long long trig_mult;
  20.  
  21. res go(int v,long long pr, int leng,int current_line, int &best_for_line)
  22. {
  23. time_trigger++;
  24. if (time_trigger==100000000)
  25. {
  26. time_trigger = 0;
  27. trig_mult++;
  28. }
  29. long long current = current_arr_size;
  30. solution[current_arr_size] = v;
  31. nexter[current_arr_size] = pr;
  32. current_arr_size++;
  33.  
  34. used[v] = true;
  35. int x = g[v].size();
  36. res best_res = make_pair(current,leng);
  37. for (int i=x-1;i>=0;i--)
  38. {
  39. int u = g[v][i];
  40. if (!used[u] && u<=current_line && trig_mult<max_trig &&
  41. current_arr_size<max_back_track_capacity-60)
  42. {
  43. res current_res = go(u,current,leng+1,current_line,best_for_line);
  44. if (best_res.second<current_res.second)
  45. {
  46. best_res = current_res;
  47. }
  48. }
  49. }
  50. if (best_res.second<best_for_line)
  51. {
  52. current_arr_size--;
  53. }
  54. else
  55. {
  56. best_for_line = best_res.second;
  57. }
  58. used[v] = false;
  59. return best_res;
  60. }
  61.  
  62. res solve(int n)
  63. {
  64. int i;
  65. for (i=0;i<maxn;i++)
  66. {
  67. used[i] = false;
  68. }
  69. time_trigger = 0;
  70. trig_mult = 0;
  71. int best_in_this_line = 0;
  72. res best_result = go(1,-1,1,n,best_in_this_line);
  73. return best_result;
  74. }
  75. typedef vector<int> vect;
  76.  
  77. void shuf(vect &vecter)
  78. {
  79. int n = vecter.size();
  80. if (n==0) return;
  81. for (int i=0;i<10000;i++)
  82. {
  83. int x = rand()%n;
  84. int y = rand()%n;
  85. swap(vecter[x],vecter[y]);
  86. }
  87. }
  88. int my_arr[9] = {50,49,48,44,40,39,38,35,34};
  89. int valuess[9] = {37,36,36,34,30,29,28,27,26};
  90. bool no_updates[9] = {false,false,false,false,false,
  91. false,false,false,false,false};
  92. int main()
  93. {
  94. #ifndef ONLINE_JUDGE
  95. freopen("input.txt","rt",stdin);
  96. freopen("output.txt","wt",stdout);
  97. #endif
  98. srand(time(0) );
  99. int i,j;
  100. int count = 0;
  101. for (i=0;i<=50;i++)
  102. {
  103. g.push_back(vector<int>());
  104. }
  105. for (i=1;i<=50;i++)
  106. for (j=i+1;j<=50;j++)
  107. {
  108. if (j%i==0)
  109. {
  110. count++;
  111. g[i].push_back(j);
  112. g[j].push_back(i);
  113. }
  114. }
  115.  
  116. int good_answers = 0;
  117. for (int xxx=0;xxx<100000;xxx++)
  118. {
  119. for (i=0;i<=50;i++)
  120. {
  121. shuf(g[i]);
  122. }
  123.  
  124. for (int yy=8;yy>=0;yy--)
  125. {
  126. if (no_updates[yy]) continue;
  127. i=my_arr[yy];
  128. current_arr_size = 0;
  129. res k = solve(i);
  130. cerr << "done for " << i << " with ans " << k.second << endl;
  131. if (k.second+2<=valuess[yy]) break;
  132. if (k.second<=valuess[yy]) continue;
  133. if (yy>2) no_updates[yy] = true;
  134. cerr << "Warning! good answer found!" << endl;
  135. good_answers++;
  136. cerr << "total_goods = " << good_answers << endl;
  137. cout << "ans for i = " << i << " is " << k.second << endl;
  138. long long x = k.first;
  139.  
  140. while (x!=-1)
  141. {
  142. vasya.push(solution[x]);
  143. x = nexter[x];
  144. }
  145. while (!vasya.empty())
  146. {
  147. cout << vasya.top() << " ";
  148. vasya.pop();
  149. }
  150. cout << endl;
  151.  
  152. }
  153. }
  154.  
  155. return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement