Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include<algorithm>
- using namespace std;
- bool comp(long long int a, long long int n,long long int b,long long int m) {
- return (a*a+n*n)*b*m > (b*b+m*m)*a*n;
- }
- int main() {
- int n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- int m;
- cin >> m;
- /*
- int stick[10000+2];
- //int* arr = new int[n]();
- for (int i = 0; i < 10002; i++) {
- stick[i] = 0;
- }
- for (int j = 0; j < m; j++) {
- int a;
- cin >> a;
- stick[a]++;
- }
- vector<int> paired(0);
- bool find4 = false;
- int n4;
- for (int j = 0; j < 10002; j++) {
- if (stick[j] >= 2) {
- paired.push_back(j);
- if (stick[j] >= 4) {
- find4 = true;
- n4 = j;
- break;
- }
- }
- }
- */
- vector<int> sticks(m);
- vector<int> paired(0);
- for (int j = 0; j < m; j++) {
- int a;
- cin >> a;
- sticks[j]=a;
- }
- sort(sticks.begin(), sticks.end());
- bool find4 = false;
- int now = -1;
- int n4;
- int cnt = 0;
- for (int j = 0; j < sticks.size(); j++) {
- if (sticks[j] == now) {
- cnt++;
- if (cnt==2) {
- paired.push_back(now);
- }
- if (cnt == 4) {
- n4 = now;
- find4 = true;
- break;
- }
- }else{
- cnt = 1;
- now = sticks[j];
- }
- }
- if (find4) {
- cout << n4 << " " << n4 << " " << n4 << " " << n4<<endl;
- }else {
- int ans_a, ans_n;
- ans_a = paired[0];
- ans_n = paired[1];
- for (int j = 2; j < paired.size(); j++) {
- if (comp(ans_a, ans_n, paired[j - 1], paired[j])) {
- ans_a = paired[j - 1];
- ans_n = paired[j];
- }
- }
- cout << ans_a << " " << ans_a << " " << ans_n << " " <<ans_n << endl;
- }
- }
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement