题目传送门

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

题解

这道题做法似乎挺单一的。

(一开始想了个假做法


向量和的长度等于所有向量在其方向上投影的长度和。

为了最大化长度的话,要能够保证所有向量在长度和的方向上投影都是正的。

所以可以枚举与向量和垂直的向量作为一个端点,那么另一个端点的方向应该和它的差距不超过 \(180\)。

所以可以双指针枚举一下左右端点,一边移动一边统计就没有问题了。


时间复杂度 \(O(n\log n)\) (就是排序的复杂度)。

#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() {
read(n);
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;
}

bzoj5099 [POI2018]Pionek 双指针的更多相关文章

  1. bzoj5099: [POI2018]Pionek

    Description 在无限大的二维平面的原点(0,0)放置着一个棋子.你有n条可用的移动指令,每条指令可以用一个二维整数向量表 示.每条指令最多只能执行一次,但你可以随意更改它们的执行顺序.棋子可 ...

  2. 【BZOJ5099】[POI2018]Pionek 几何+双指针

    [BZOJ5099][POI2018]Pionek Description 在无限大的二维平面的原点(0,0)放置着一个棋子.你有n条可用的移动指令,每条指令可以用一个二维整数向量表示.每条指令最多只 ...

  3. [POI2018]Pionek

    [POI2018]Pionek 题目大意: 在无限大的二维平面的原点放置着一个棋子.你有\(n(n\le2\times10^5)\)条可用的移动指令,每条指令可以用一个二维整数向量表示.请你选取若干条 ...

  4. bzoj 5099 [POI2018]Pionek 计算几何 极角排序

    [POI2018]Pionek Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 269  Solved: 80[Submit][Status][Disc ...

  5. 【bzoj5099】[POI2018]Pionek 双指针法

    题目描述 给你 $n$ 个平面向量,选出它们中的一部分,使得它们的和的长度最大.求这个最大长度的平方. 输入 第一行包含一个正整数n(n<=200000),表示指令条数. 接下来n行,每行两个整 ...

  6. bzoj 5099: [POI2018]Pionek

    题解: 还是比较简单的一道题 考虑现在有一个向量,当且仅当下一个向量与它夹角<90度这个向量的模长才会增加 接下来怎么做呢 如果我们去枚举初始向量,向量方向会随着新增向量而变化 随着不断顺时针的 ...

  7. POI2018

    [BZOJ5099][POI2018]Pionek(极角排序+two pointers) 几个不会严谨证明的结论: 1.将所有向量按极角排序,则答案集合一定是连续的一段. 当答案方向确定时,则一个向量 ...

  8. [BZOJ5099]Pionek

    Description 给 \(n\) (\(n\le 2\times 10 ^5\)) 个向量,现在你在 \((0,0)\) ,选择一些向量使你走的最远. Solution 自己的想法:按极角排序后 ...

  9. BZOJ 5099: Pionek(双指针)(占位)

    pro:有N个向量,你可以选择一些向量,使得其向量和离原点最远. 输出这个欧几里得距离的平方. sol:(感觉网上的证明都不是很充分,我自己也是半信半疑吧)日后证明了再补. #include<b ...

随机推荐

  1. leetcode-mid-math-29. Divide Two Integers-NO

    mycode   91.28% class Solution(object): def divide(self, dividend, divisor): """ :typ ...

  2. python读取文件乱码

    方法一:使用codecs import codecs f = codecs.open('nlpir/Readme.txt','r','GBK') line = f.readline() while l ...

  3. java kryo序列化与反序列化

    https://blog.csdn.net/lan12334321234/article/details/84907492 问题: https://blog.csdn.net/baidu_384041 ...

  4. CentOS 6.5 编译安装Apache2.4

    一. httpd 2.4的新特 1) MPM支持运行时装载 --enable-mpms-shared=all --with-mpm=prefork|worker|event2) 支持event MPM ...

  5. mysql5.7无法启动原因排查

    前天刚刚拷了同事最新的MySQL5.7,安装成功后运行良好,今天却无法启动,Navicat也无法连接. 开始排查原因: 1.进入dos命令窗口,输入net start mysql启动,提示 百度出现错 ...

  6. Intellij Idea使用教程汇总篇

    Java编程强大的工具IDEA使用教程及一些快捷键收藏如下: https://blog.csdn.net/fanrenxiang/article/details/80503490

  7. 【转】centos7安装

    转自:https://blog.csdn.net/qq_42570879/article/details/82853708 1.CentOS下载CentOS是免费版,推荐在官网上直接下载,网址:htt ...

  8. 【JZOJ 3918】蛋糕

    题面: 正文: 根据数据\(4\leq R,C\leq 75\)我们大概可以先枚举切横的刀再二分答案. 更具体的: 假设我们已经枚举到这样横切: 再假设我们已经二分到最小的巧克力是\(7\) 康康第一 ...

  9. 洛谷P1484 种树&洛谷P3620 [APIO/CTSC 2007]数据备份 题解(堆+贪心)

    洛谷P1484 种树&洛谷P3620 [APIO/CTSC 2007]数据备份 题解(堆+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/132 ...

  10. 19: vue项目使用整理

    1.1  axios 基本用法 安装:npm install axios -S                   # 也可直接下载axios.min.js文件 1.axios借助Qs对提交数据进行序 ...