萌萌哒萌新求助简单题 92pts,感激不尽喵
查看原帖
萌萌哒萌新求助简单题 92pts,感激不尽喵
852144
Loser_Syx楼主2024/7/15 16:47
#include <iostream>
#include <cassert>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define int long long
#define pii pair<int, int>
#define eb emplace_back
#define F first
#define S second
#define test(x) cout << "Test: " << x << '\n'
#define lowbit(x) (x & -x)
#define debug puts("qwq");
#define open(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define close fclose(stdin);fclose(stdout);
namespace FastIO {
	template <typename T = int>
	inline T read() {
		T s = 0, w = 1;
		char c = getchar();
		while (!isdigit(c)) {
			if (c == '-') w = -1;
			c = getchar();
		}
		while (isdigit(c)) s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
		return s * w;
	}
	template <typename T>
	inline void read(T &s) {
		s = 0;
		int w = 1;
		char c = getchar();
		while (!isdigit(c)) {
			if (c == '-') w = -1;
			c = getchar();
		}
		while (isdigit(c)) s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
		s = s * w;
	}
	template <typename T, typename... Arp> inline void read(T &x, Arp &...arp) {
		read(x), read(arp...);
	}
	template <typename T>
	inline void write(T x, char ch) {
		if (x < 0) x = -x, putchar('-');
		static char stk[25];
		int top = 0;
		do {
			stk[top++] = x % 10 + '0', x /= 10;
		} while (x);
		while (top) putchar(stk[--top]);
		putchar(ch);
		return;
	}
	template <typename T>
	inline void smax(T &x, T y) {
		if (x < y) x = y;
	}
	template <typename T>
	inline void smin(T &x, T y) {
		if (x > y) x = y;
	}
	void quit() {
		exit(0);
	}
} using namespace FastIO;
const double pi = acos(-1);
const int N = 2e5 + 19;
struct node {
	int x, y;
	double angle;
	bool operator < (const node &a) const {
		return angle < a.angle;
	}
} a[N << 1];
signed main() {
	int n, ans = 0;
	read(n);
	for (int i = 1; i <= n; ++i) read(a[i].x, a[i].y), a[i].angle = atan2(a[i].y, a[i].x);
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; ++i) a[n + i] = {a[i].x, a[i].y, a[i].angle + pi * 2};
	for (int l = 1, r = 1, sx = 0, sy = 0; l <= n; ++l) {
		while (r - l < n && fabs(a[r].angle - a[l].angle) < pi) { sx += a[r].x; sy += a[r++].y; }
		smax(ans, sx * sx + sy * sy);
		sx -= a[l].x; sy -= a[l].y;
		smax(ans, sx * sx + sy * sy);
	} write(ans, '\n');
	return 0;
}
2024/7/15 16:47
加载中...