Advertisement
Guest User

Untitled

a guest
Aug 18th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include<algorithm>
  5. using namespace std;
  6. bool comp(long long int a, long long int n,long long int b,long long int m) {
  7.     return (a*a+n*n)*b*m > (b*b+m*m)*a*n;
  8. }
  9. int main() {
  10.     int n;
  11.     cin >> n;
  12.     for (int i = 0; i < n; i++) {
  13.         int m;
  14.         cin >> m;
  15.         /*
  16.         int stick[10000+2];
  17.         //int* arr = new int[n]();
  18.         for (int i = 0; i < 10002; i++) {
  19.             stick[i] = 0;
  20.         }
  21.         for (int j = 0; j < m; j++) {
  22.             int a;
  23.             cin >> a;
  24.             stick[a]++;
  25.         }
  26.         vector<int> paired(0);
  27.         bool find4 = false;
  28.         int n4;
  29.         for (int j = 0; j < 10002; j++) {
  30.             if (stick[j] >= 2) {
  31.                 paired.push_back(j);
  32.                 if (stick[j] >= 4) {
  33.                     find4 = true;
  34.                     n4 = j;
  35.                     break;
  36.                 }
  37.             }
  38.         }
  39.         */
  40.         vector<int> sticks(m);
  41.         vector<int> paired(0);
  42.  
  43.         for (int j = 0; j < m; j++) {
  44.             int a;
  45.             cin >> a;
  46.             sticks[j]=a;
  47.         }
  48.         sort(sticks.begin(), sticks.end());
  49.         bool find4 = false;
  50.         int now = -1;
  51.         int n4;
  52.         int cnt = 0;
  53.         for (int j = 0; j < sticks.size(); j++) {
  54.             if (sticks[j] == now) {
  55.                 cnt++;
  56.                 if (cnt==2) {
  57.                     paired.push_back(now);
  58.                 }
  59.                 if (cnt == 4) {
  60.                     n4 = now;
  61.                     find4 = true;
  62.                     break;
  63.                 }
  64.             }else{
  65.                 cnt = 1;
  66.                 now = sticks[j];
  67.             }
  68.         }
  69.  
  70.         if (find4) {
  71.             cout << n4 << " " << n4 << " " << n4 << " " << n4<<endl;
  72.         }else {
  73.             int ans_a, ans_n;
  74.             ans_a = paired[0];
  75.             ans_n = paired[1];
  76.             for (int j = 2; j < paired.size(); j++) {
  77.                 if (comp(ans_a, ans_n, paired[j - 1], paired[j])) {
  78.                     ans_a = paired[j - 1];
  79.                     ans_n = paired[j];
  80.                 }
  81.             }
  82.  
  83.             cout << ans_a << " " << ans_a << " " << ans_n << " " <<ans_n << endl;
  84.         }
  85.  
  86.     }
  87.     //system("pause");
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement