Skip to content

Instantly share code, notes, and snippets.

@na-o-ys
Last active August 29, 2015 14:14
Show Gist options
  • Save na-o-ys/920922ef5803f6c01e75 to your computer and use it in GitHub Desktop.
Save na-o-ys/920922ef5803f6c01e75 to your computer and use it in GitHub Desktop.
Rockethon 2015
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
int main()
{
int n;
ll m;
cin >> n >> m;
vector<int> head, tail;
for (int i = 1; i < n; i++) {
if (m <= (1ll << n-i-1)) {
head.push_back(i);
} else {
tail.push_back(i);
m -= (1ll << n-i-1);
}
}
head.push_back(n);
for (int v : head) cout << v << " ";
reverse(all(tail));
for (int v : tail) cout << v << " ";
cout << endl;
return 0;
}
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
using namespace std;
int main()
{
int n; cin >> n;
vector<int> l(n), r(n);
loop (n, i) cin >> l[i] >> r[i];
double ans = 0;
loop (n, snd) for (int v = l[snd]; v <= r[snd]; v++) {
loop (n, fst) if (fst != snd) {
double prod = 1.0 / (r[snd] - l[snd] + 1);
loop (n, i) if (i != snd) {
// Pr(price[i] < v) for i < snd
// Pr(price[i] <= v) for i > snd
int right = min(r[i], v - (i < snd));
double x = max(right - l[i] + 1, 0);
double p_lt = x / (r[i] - l[i] + 1);
prod *= (i == fst ? 1.0 - p_lt : p_lt);
}
ans += prod * v;
}
}
printf("%.12f\n", ans);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment