Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <fstream>
  6. #include <string>
  7. #include <cstdlib>
  8. #include <random>
  9.  
  10. #define assert_input(expr)    if (!(expr)) {cout << score << endl; return 0;}
  11.  
  12. using namespace std;
  13.  
  14. int main(int argc, char** argv) {
  15.     int n;
  16.     cin >> n;
  17.  
  18.     vector<int> task_cat(n);
  19.  
  20.     for (int i = 0; i < n; i++) {
  21.         cin >> task_cat[i];
  22.         task_cat[i]--;
  23.     }
  24.  
  25.     vector<double> est_time(n);
  26.  
  27.     for (int i = 0; i < n; i++) {
  28.         cin >> est_time[i];
  29.     }
  30.  
  31.     int m;
  32.     cin >> m;
  33.  
  34.     vector<vector<double>> time_ratio(m, vector<double>(4));
  35.  
  36.     for (int i = 0; i < m; i++) {
  37.         for (int j = 0; j < 4; j++) {
  38.             cin >> time_ratio[i][j];
  39.         }
  40.     }
  41.  
  42.     int score = 0;
  43.     // bool pe = false;
  44.  
  45.     auto calc_time = [&](const vector<int>& w) {
  46.         vector<double> real_time(m);
  47.  
  48.         double total_time = 0;
  49.         for (int i = 0; i < n; i++) {
  50.             auto wid = w[i];
  51.             real_time[wid] += time_ratio[wid][task_cat[i]] * est_time[i];
  52.             total_time = max(total_time, real_time[wid]);
  53.         }
  54.         return total_time;
  55.     };
  56.  
  57.     double best_time = 1e9;
  58.     vector<int> best_distr;
  59.     srand(123);
  60.     for (int i = 0; i < 100000; i++) {
  61.         vector<int> w(n);
  62.         for (int j = 0; j < n; j++) {
  63.             w[j] = rand() % m;
  64.         }
  65.  
  66.         double total_time = calc_time(w);
  67.         if (total_time < best_time) {
  68.             best_time = total_time;
  69.             best_distr = w;
  70.         }
  71.     }
  72.  
  73.     for (auto wid : best_distr) {
  74.         cout << wid + 1 << " ";
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement