# bzoj5099 [POI2018]Pionek 双指针

## 题目传送门

https://lydsy.com/JudgeOnline/problem.php?id=5099

## 题解

（一开始想了个假做法

#include<bits/stdc++.h>

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I> inline void read(I &x) {
int f = 0, c;
while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
x = c & 15;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
f ? x = -x : 0;
}

const int N = 200000 * 2 + 7;
const double PI = 3.1415926535897932384626433;

int n;

struct Node {
ll x, y;
double a;
inline Node(const ll &x = 0, const ll &y = 0) : x(x), y(y) {}
inline ll glen() { return x * x + y * y; }
inline Node operator + (const Node &b) { return Node(x + b.x, y + b.y); }
inline Node operator - (const Node &b) { return Node(x - b.x, y - b.y); }
inline bool operator < (const Node &b) const { return a < b.a; }
} a[N], s[N];

inline void work() {
int p = 1;
ll ans = 0;
for (int i = 1; i <= n; ++i) {
smax(p, i);
smax(ans, (s[p] - s[i - 1]).glen());
while (p < i + n - 1 && a[p + 1].a <= a[i].a + PI) ++p, smax(ans, (s[p] - s[i - 1]).glen());
}
printf("%lld\n", ans);
}

inline void init() {
for (int i = 1; i <= n; ++i) read(a[i].x), read(a[i].y), a[i].a = atan2(a[i].y, a[i].x);
std::sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) a[i + n] = a[i], a[i + n].a = a[i].a + PI * 2;
for (int i = 1; i <= (n << 1); ++i) s[i] = s[i - 1] + a[i];
}

int main() {
#ifdef hzhkk
freopen("hkk.in", "r", stdin);
#endif
init();
work();
fclose(stdin), fclose(stdout);
return 0;
}

posted @ 2019-10-31 09:40  hankeke  阅读(72)  评论(0编辑  收藏  举报