Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- #include<vector>
- #include<stack>
- #include<ctime>
- using namespace std;
- const int maxn=60;
- bool used[maxn];
- vector<vector<int> > g;
- typedef pair<long long,int> res;
- stack<long long> vasya;
- long long time_trigger;
- const long long max_trig = 2;
- const int max_back_track_capacity = 1000060;
- int solution[max_back_track_capacity];
- int nexter[max_back_track_capacity];
- int current_arr_size;
- long long trig_mult;
- res go(int v,long long pr, int leng,int current_line, int &best_for_line)
- {
- time_trigger++;
- if (time_trigger==100000000)
- {
- time_trigger = 0;
- trig_mult++;
- }
- long long current = current_arr_size;
- solution[current_arr_size] = v;
- nexter[current_arr_size] = pr;
- current_arr_size++;
- used[v] = true;
- int x = g[v].size();
- res best_res = make_pair(current,leng);
- for (int i=x-1;i>=0;i--)
- {
- int u = g[v][i];
- if (!used[u] && u<=current_line && trig_mult<max_trig &&
- current_arr_size<max_back_track_capacity-60)
- {
- res current_res = go(u,current,leng+1,current_line,best_for_line);
- if (best_res.second<current_res.second)
- {
- best_res = current_res;
- }
- }
- }
- if (best_res.second<best_for_line)
- {
- current_arr_size--;
- }
- else
- {
- best_for_line = best_res.second;
- }
- used[v] = false;
- return best_res;
- }
- res solve(int n)
- {
- int i;
- for (i=0;i<maxn;i++)
- {
- used[i] = false;
- }
- time_trigger = 0;
- trig_mult = 0;
- int best_in_this_line = 0;
- res best_result = go(1,-1,1,n,best_in_this_line);
- return best_result;
- }
- typedef vector<int> vect;
- void shuf(vect &vecter)
- {
- int n = vecter.size();
- if (n==0) return;
- for (int i=0;i<10000;i++)
- {
- int x = rand()%n;
- int y = rand()%n;
- swap(vecter[x],vecter[y]);
- }
- }
- int my_arr[9] = {50,49,48,44,40,39,38,35,34};
- int valuess[9] = {37,36,36,34,30,29,28,27,26};
- bool no_updates[9] = {false,false,false,false,false,
- false,false,false,false,false};
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt","rt",stdin);
- freopen("output.txt","wt",stdout);
- #endif
- srand(time(0) );
- int i,j;
- int count = 0;
- for (i=0;i<=50;i++)
- {
- g.push_back(vector<int>());
- }
- for (i=1;i<=50;i++)
- for (j=i+1;j<=50;j++)
- {
- if (j%i==0)
- {
- count++;
- g[i].push_back(j);
- g[j].push_back(i);
- }
- }
- int good_answers = 0;
- for (int xxx=0;xxx<100000;xxx++)
- {
- for (i=0;i<=50;i++)
- {
- shuf(g[i]);
- }
- for (int yy=8;yy>=0;yy--)
- {
- if (no_updates[yy]) continue;
- i=my_arr[yy];
- current_arr_size = 0;
- res k = solve(i);
- cerr << "done for " << i << " with ans " << k.second << endl;
- if (k.second+2<=valuess[yy]) break;
- if (k.second<=valuess[yy]) continue;
- if (yy>2) no_updates[yy] = true;
- cerr << "Warning! good answer found!" << endl;
- good_answers++;
- cerr << "total_goods = " << good_answers << endl;
- cout << "ans for i = " << i << " is " << k.second << endl;
- long long x = k.first;
- while (x!=-1)
- {
- vasya.push(solution[x]);
- x = nexter[x];
- }
- while (!vasya.empty())
- {
- cout << vasya.top() << " ";
- vasya.pop();
- }
- cout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement