#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <iomanip>
using namespace std;
vector<double> power(vector<double> a, double b)
{
vector<double> ret;
for (int i = 0; i < a.size() ; i++)
{
ret.push_back(pow(a[i], b));
}
return ret;
}
double sumarr(vector<double> a)
{
double sss = 0;
for (int i = 0; i < a.size() ; i++)
{
sss += a[i];
}
return sss;
}
vector<double> operator- (vector<double> a, vector<double> b)
{
vector<double> ret;
for (int i = 0; i < a.size() ; i++)
{
ret.push_back(a[i] - b[i]);
}
return ret;
}
vector<double> sortvect(vector<double> a)
{
double temp;
for (int i = 0; i < a.size() ; i++)
{
for (int j = a.size()-1 ; j > i; j--)
{
if (a[i]>a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
return a;
}
vector<double> getrank(vector<double> a)
{
vector<double> ranks(a.size());
vector<double> b(sortvect(a));
for (int i = 0; i < a.size() ; i++)
{
for (int j = 0; j < b.size() ; j++)
{
if (a[i] == b[j])
{
ranks.push_back(j);
break;
}
}
}
return ranks;
}
int main()
{
double n;
cin >> n;
vector<double> x,y;
double a;
for (int i = 0; i < n; i++)
{
cin >> a;
x.push_back(a);
}
for (int i = 0; i < n; i++)
{
cin >> a;
y.push_back(a);
}
vector<double> rankx(getrank(x));
vector<double> ranky(getrank(y));
vector<double> diff(rankx-ranky);
double sumds = sumarr(power(diff,2));
cout << fixed << setprecision(3) << 1 - (6 * sumds) / (n*(n*n - 1));
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.