Skip to content

Instantly share code, notes, and snippets.

@iray-tno
Created January 17, 2016 18:32
Show Gist options
  • Save iray-tno/dc34e30bc9f00c2a8f39 to your computer and use it in GitHub Desktop.
Save iray-tno/dc34e30bc9f00c2a8f39 to your computer and use it in GitHub Desktop.
#include <queue>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <iterator>
#include <cmath>
#include <tuple>
#include <stack>
#include <iomanip>
#include <string>
#include <vector>
#include <limits>
using namespace std;
long double solve(){
long long n,a,b;
cin >> n >> a >> b;
vector<int> c(n);
long long sum = 0;
for(int i = 0; i < n; ++i){
cin >> c[i];
sum += c[i];
}
long double cycle = 0;
for(int i = 0; i < n; ++i){
cycle += c[i]*c[i]/2.0;
}
auto calc = [&](long long max){
long double ret = max/sum*cycle;
long long mod = max%sum;
for(int i = 0; i < n; ++i){
if(mod<=c[i]){
ret += mod*mod/2.0;
break;
}else{
ret += c[i]*c[i]/2.0;
mod -= c[i];
}
}
return ret;
};
long double ret = (calc(b)-calc(a))/(b-a);
return ret;
}
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int t;
cin >> t;
for(int i = 0; i < t; ++i){
cout << "Case #" << i+1 << ": " << solve() << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment