Hard challenge(HDU6127)
来源:互联网 发布:java.io.temp 编辑:程序博客网 时间:2024/05/18 20:11
题意:给定N个点,每个点都有一个value,每两个点都连一条线段,这条线段的value是两个端点的value值的乘积,现在划一条经过原点的直线,这条直线经过的左右线段的value值的和即为直线的value,题目要求最大的直线的value
分析:题目可以转化为枚举每一个点,用原点和枚举的点确定的直线将所有点划分为两部分,其实这条直线的value就是直线两边的点的value值的和的乘积,因此这题先对所有点极角排序,然后枚举所有即可。
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <map>#include <set>#include <vector>#include <queue>#include <cmath>#include <bitset>using namespace std;const int MAXN = 50005;typedef long long ll;struct point{ ll x, y, value; bool operator < (const point& ano) const { if(y * ano.y < 0) return y > ano.y; if( (y == 0 && ano.y < 0) || (y < 0 && ano.y == 0)) return y > ano.y; return x * ano.y - y * ano.x > 0;//正是因为这里有x * y, x,y的数据量为1e9 //一开始用的是int,会溢出,从而WA了好几次 }}ps[MAXN];int main(){ //freopen("1008.in", "r", stdin); //freopen("out.out", "w", stdout); int CASE; scanf("%d", &CASE); while (CASE--) { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%lld%lld%lld", &ps[i].x, &ps[i].y, &ps[i].value); } sort(ps, ps + n); //for(int i = 0; i < n; ++i) //printf("%d %d %d\n", ps[i].x, ps[i].y, ps[i].value); int pos = -1; ll s1 = 0LL, s2 = 0LL; for (int i = 0; i < n; ++i) { if(ps[i].y >= 0) s1 += ps[i].value; else { if(pos == -1) pos = i; s2 += ps[i].value; } } if(pos == -1) pos = 0; ll ans = s1 * s2; int i = 0; if(ps[0].y == 0) i += 1, ans = max(ans, (s1 - ps[0].value) * (s2 + ps[0].value)); for( ; i < n; ++i) { if(i > 0) s1 -= ps[i - 1].value, s2 += ps[i - 1].value; while(-ps[pos].y * ps[i].x + ps[pos].x * ps[i].y < 0) { s1 += ps[pos].value; s2 -= ps[pos].value; pos = (pos + 1) % n; } ans = max(ans, max(s1 * s2, (s1 - ps[i].value) * (s2 + ps[i].value))); } printf("%lld\n", ans); } return 0;}
阅读全文
0 0
- hdu6127 Hard challenge
- HDU6127-Hard challenge
- hdu6127 Hard challenge
- Hard challenge(HDU6127)
- HDU6127-Hard challenge
- HDU6127-Hard challenge
- HDU6127-Hard challenge
- HDU6127 Hard challenge【几何】
- Hard challenge(hdu6127)
- HDU6127 Hard challenge[计算几何]
- HDU6127 Hard challenge 极角排序|暴力
- Hdu6127 Hard challenge(2017多校第7场)
- hdu6127-!!多校7&极角排序&问题转化-Hard challenge
- hdu6127 Hard challenge 2017多校第七场1008 计算几何 极角排序+双指针
- hard challenge
- Hard challenge
- HDU 6127 Hard challenge
- hdu 6127 Hard challenge
- servlet 3.0 版本特性
- hdu Just do it 组合数规律
- Bootstrap Table使用整理(四)-工具栏
- LCD驱动-JZ2440
- Java内存模型和垃圾回收
- Hard challenge(HDU6127)
- hdu6130Kolakoski(第七场打表)
- laravel上传图片
- SNMP详解
- 笨办法学 Python · 续 练习 47:`bc`
- HDU 6129 Just do it【杨辉三角】【思维题】【好题】
- SQL SERVER 查自动本月,本年,本日的数据条件
- golang中发送http请求的几种常见情况
- apache ab开源的压力测试工具参数介绍