B - Pond Cascade
优先队列维护这个水池需要多少时间 或者 直接扫一遍。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int maxn = 100000 + 10; const int INF = 2e9; LL a[maxn], sum[maxn]; int main() { int n; LL flow; while(~scanf("%d%lld", &n, &flow)) { for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); double t1 = INF, sum1 = 0, t2 = -INF, sum2 = 0; for (int i = n; i >= 1; i--) sum1 += a[i], t1 = min(t1, sum1*1.0/(n-i+1)/flow); for (int i = 1; i <= n; i++) sum2 += a[i], t2 = max(t2, sum2*1.0/i/flow); printf("%.8lf %.8lf ", t1, t2); } }
D - Equinox Roller Coaster
N个点,找出一个可以构成的最大的正方形,并且正方形的边都与坐标轴平行。
对于每个X/Y坐标建一个表。对于每个点,枚举它X/Y坐标对应的表中所有的点(选size较小的那一维),然后判断剩下的另外两个点是否存在。
#include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <set> #include <vector> using namespace std; const int maxn = 100000 + 100; map<int, set<int> > px, py; int x[maxn], y[maxn]; int main() { int n; while(~scanf("%d", &n)) { px.clear(), py.clear(); for (int i = 1; i <= n; i++) { scanf("%d%d", &x[i], &y[i]); px[x[i]].insert(y[i]), py[y[i]].insert(x[i]); } int ans = 0; for (int i = 1; i <= n; i++) { if (px[x[i]].size() < py[y[i]].size()) for (auto j = px[x[i]].begin(); j != px[x[i]].end(); j++) { if ((*j) == y[i]) continue; int dis = (*j) - y[i]; if (px[x[i] + dis].count(y[i]) && px[x[i] + dis].count(*j)) ans = max(ans, dis); } else for (auto j = py[y[i]].begin(); j != py[y[i]].end(); j++) { if ((*j) == x[i]) continue; int dis = (*j) - x[i]; if (py[y[i] + dis].count(x[i]) && py[y[i] + dis].count(*j)) ans = max(ans, dis); } } printf("%d ", ans); } }