2017杭电多校第七场1008 Hard challenge(级角排序)HDU 6127
来源:互联网 发布:淘宝玉石店铺推荐 编辑:程序博客网 时间:2024/06/07 16:22
Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1258 Accepted Submission(s): 533
Problem Description
There are n points on the plane, and the i th points has a value vali , and its coordinate is (xi,yi) . It is guaranteed that no two points have the same coordinate, and no two points makes the line which passes them also passes the origin point. For every two points, there is a segment connecting them, and the segment has a value which equals the product of the values of the two points. Now HazelFan want to draw a line throgh the origin point but not through any given points, and he define the score is the sum of the values of all segments that the line crosses. Please tell him the maximum score.
Input
The first line contains a positive integer T(1≤T≤5) , denoting the number of test cases.
For each test case:
The first line contains a positive integern(1≤n≤5×104) .
The nextn lines, the i th line contains three integers xi,yi,vali(|xi|,|yi|≤109,1≤vali≤104) .
For each test case:
The first line contains a positive integer
The next
Output
For each test case:
A single line contains a nonnegative integer, denoting the answer.
A single line contains a nonnegative integer, denoting the answer.
Sample Input
221 1 11 -1 131 1 11 -1 10-1 0 100
Sample Output
11100
Source
2017 Multi-University Training Contest - Team 7
Recommend
liuyiding | We have carefully selected several similar problems for you: 6132 6131 6130 6129 6128
题目大意:给定 n 个点,和权值,他们两两相连,每条边的权值就是他们两个点权值的乘积,任意两点之间的直线不经过原点,让你从原点划一条直线,使得经过的直线的权值和最大。
解题思路:极角排序后扫描一圈比大小。
AC代码
#include <bits/stdc++.h>using namespace std;#define MP make_pair#define PB push_backtypedef long long LL;typedef pair<int,int> PII;const double eps=1e-8;const double pi=acos(-1.0);const int K=1e6+7;const int mod=1e9+7;struct Point{ LL x,y,v;}pt[K],st;LL cross(const Point &po,const Point &ps,const Point &pe){ return (ps.x-po.x)*(pe.y-po.y)-(pe.x-po.x)*(ps.y-po.y);}bool cmp(const Point &ta,const Point &tb){ return cross(st,ta,tb)>0;}int main(void){ int t,n;cin>>t; while(t--) { int se; LL s1=0,s2=0,ans=0,mx=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%lld%lld%lld",&pt[i].x,&pt[i].y,&pt[i].v); pt[i+n].x=-pt[i].x; pt[i+n].y=-pt[i].y; pt[i+n].v=0; s2+=pt[i].v; } if(n==1) {printf("0\n");continue;} sort(pt,pt+2*n,cmp); s1+=pt[0].v; for(int i=1;i<2*n;i++) if(cross(st,pt[0],pt[i])<0) { se=i-1;break; } else s1+=pt[i].v; s2-=s1; mx=ans=s1*s2; for(int i=1,r=se;i<se;i++) { ans+=-pt[i].v*s2+(s1-pt[i].v)*pt[i].v; s2+=pt[i].v,s1-=pt[i].v; while(r+1<2*n&&cross(st,pt[i],pt[r+1])>=0) { r++; ans+=-pt[r].v*s1+(s2-pt[r].v)*pt[r].v; s1+=pt[r].v,s2-=pt[r].v; } mx=max(mx,ans); } printf("%lld\n",mx); } return 0;}
阅读全文
0 0
- 2017杭电多校第七场1008 Hard challenge(级角排序)HDU 6127
- hdu61272017杭电多校第七场1008Hard challenge
- hdu6127 Hard challenge 2017多校第七场1008 计算几何 极角排序+双指针
- HDU 6127 Hard challenge(几何 多校第七场)
- HDU 6127 Hard challenge(级角排序)
- HDU 6127 Hard challenge【极角排序】
- HDU 6127 Hard challenge(极角排序+模拟)
- HDU 6127 Hard challenge (极角排序+二分, 2017 Multi-Univ Training Contest 7)
- HDU 6127 Hard challenge(极角排序+枚举点)
- HDU 6127 Hard challenge 计算几何 极角排序
- HDU 6127 Hard challenge
- hdu 6127 Hard challenge
- hdu--6127--Hard challenge
- HDU 6127 Hard challenge
- HDU 6127 Hard challenge
- hdu 6127 Hard challenge
- HDU 6127 Hard challenge
- hdu 6127 Hard challenge
- POJ 2516 Minimum Cost(最小费用最大流)
- ble连接之后onServicesDiscovered 不被调用
- MyBatis 入门开发 ----输入,输出参数
- 顺序表-改(移动)
- 浅谈sql中的in与not in,exists与not exists的区别以及性能分析
- 2017杭电多校第七场1008 Hard challenge(级角排序)HDU 6127
- CSS 浮动规则
- 程序员高效编程的14点建议
- 列表、列表解析、过滤器filter和map
- 数据结构实验之二叉树一:树的同构
- PCA算法
- oracle restore
- Web 安全 PHP 代码审查之常规漏洞
- 2017年8月16日训练日记