Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <string>
  5. #include <map>
  6. #include <algorithm>
  7. #include <fstream>
  8. #include <queue>
  9. #include <cmath>
  10. #include <unordered_map>
  11.  
  12. using namespace std;
  13.  
  14. #define endl '\n'
  15.  
  16. struct point {
  17.     long long x, y, num;
  18.     point(long long x = 0, long long y = 0, long long num = 0) : x(x), y(y), num(num) {}
  19. };
  20.  
  21. long long len(point a) {
  22.     return a.x * a.x + a.y * a.y;
  23. }
  24.  
  25. bool cmp(point a, point b) {
  26.     return len(a) > len(b);
  27. }
  28.  
  29. point operator+(point a, point b) {
  30.     point tmp;
  31.     tmp.x = a.x + b.x;
  32.     tmp.y = a.y + b.y;
  33.     return tmp;
  34. }
  35.  
  36. point operator-(point a, point b) {
  37.     point tmp;
  38.     tmp.x = a.x - b.x;
  39.     tmp.y = a.y - b.y;
  40.     return tmp;
  41. }
  42.  
  43. int main() {   
  44.     ios_base::sync_with_stdio(false);
  45.     cin.tie(0);
  46.    
  47.     int n;
  48.     cin >> n;
  49.  
  50.     vector<point> shit(n);
  51.     vector<point> data(n);
  52.     for (int i = 0; i < n; i++) {
  53.         cin >> data[i].x >> data[i].y;
  54.         shit[i] = data[i];
  55.         data[i].num = i;
  56.     }
  57.  
  58.     vector<int> ans(n);
  59.     for (int i = 0; i < 100; i++) {
  60.         random_shuffle(data.begin(),data.end());
  61.         point s = point(0, 0);
  62.         for (int i = 0; i < n; i++) {
  63.             if (len(s + data[i]) <= len(s - data[i])) {
  64.                 s = s + data[i];
  65.                 ans[data[i].num] = 1;
  66.             }
  67.             else {
  68.                 s = s - data[i];
  69.                 ans[data[i].num] = -1;
  70.             }
  71.         }
  72.         if (len(s) <= 1500000ll * 1500000ll) {
  73.             break;
  74.         }
  75.     }
  76.  
  77.     for (int i = 0; i < n; i++) {
  78.         cout << ans[i] << " ";
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement