Created
February 5, 2016 19:59
-
-
Save Noobgam/94c3b448b617fc68d1cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
#include <ctime> | |
#include <vector> | |
#include <set> | |
#include <iostream> | |
#include <cstring> | |
#include <algorithm> | |
#include <string> | |
#include <map> | |
using namespace std; | |
#define pii pair <int, int> | |
int n[100], m[100]; | |
long double ans = 1e9; | |
int besta, bestb, bestc, bestd; | |
int gcd(int a, int b) | |
{ | |
while (a != 0 && b != 0) | |
{ | |
if (a > b) | |
a %= b; | |
else | |
b %= a; | |
} | |
return a ? a : b; | |
} | |
void print(int a) | |
{ | |
int g = gcd(n[a], m[a]); | |
g = 1; | |
cout << n[a] / g << "/" << m[a] / g; | |
} | |
vector <int> v; | |
bool cmp(int a, int b) | |
{ | |
return n[a] * m[b] < n[b] * m[a]; | |
} | |
bool cmp2(pii a, pii b) | |
{ | |
return (n[a.first] + n[a.second]) * (m[b.first] + m[b.second]) < (n[b.first] + n[b.second]) * (m[a.first] + m[a.second]); | |
} | |
int main() | |
{ | |
freopen("a.out", "w", stdout); | |
::ios_base::sync_with_stdio(false); | |
cin.tie(0); | |
cout.tie(0); | |
int k; | |
cin >> k; | |
srand(17); | |
for (int i = 0; i < k; i++) | |
n[i] = i + 1, m[i] = i + 1, v.push_back(i); | |
random_shuffle(n, n + k); | |
random_shuffle(m, m + k); | |
sort(v.begin(), v.end(), cmp); | |
vector <pii> vv; | |
for (int a = 0; a < k; a++) | |
for (int b = 0; b < k; b++) | |
if (a != b) | |
vv.push_back(pii(a, b)); | |
sort(vv.begin(), vv.end(), cmp2); | |
for (auto x : vv) | |
{ | |
print(x.first); | |
cout << " + "; | |
print(x.second); | |
cout << endl; | |
} | |
for (int a = 0; a < k; a++) | |
for (int b = 0; b < k; b++) | |
for (int c = 0; c < k; c++) | |
for (int d = 0; d < k; d++) | |
{ | |
if (a == b || a == c || a == d) continue; | |
if (b == c || b == d) continue; | |
if (c == d) continue; | |
if (n[a] * m[b] >= n[b] * m[a]) | |
if (n[c] * m[d] >= n[d] * m[c]) | |
{ | |
long double q = (n[a] + n[c]) * (m[b] + m[d]) - (n[b] + n[d]) * (m[a] + m[c]); | |
q /= (m[a] + m[c]) * (m[b] + m[d]); | |
if (ans > q) | |
{ | |
ans = q; | |
besta = a; | |
bestb = b; | |
bestc = c; | |
bestd = d; | |
} | |
} | |
} | |
//for (int i = 0; i < k; i++) | |
// print(v[i]), cout << " "; | |
cout << endl; | |
print(besta); | |
cout << " : "; | |
print(bestb); | |
cout << endl; | |
print(bestc); | |
cout << " : "; | |
print(bestd); | |
cout << endl; | |
cout << ans; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment