HDU 6127 Hard challenge(几何)
来源:互联网 发布:淘宝好看的小白鞋 编辑:程序博客网 时间:2024/06/05 08:20
Hard challenge
Problem Description
There are n points on the plane, and the ith 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 integer n(1≤n≤5×104).
The next n lines, the ith line contains three integers xi,yi,vali(|xi|,|yi|≤109,1≤vali≤104).
Output
For each test case:A single line contains a nonnegative integer, denoting the answer.
Sample Input
22
1 1 1
1 -1 1
3
1 1 1
1 -1 10
-1 0 100
Sample Output
11100
Source
2017 Multi-University Training Contest - Team 7
题意:有n个点,给出每个点的坐标和value,相互连接,形成n*(n-1)/2条线段,每条线段的value等于两端点的value相乘。找出一个过原点的直线,使得与其相交的线段value值和最大。
题解:对于一条直线,线段权值和实际上就等于其两边点权和的乘积。把所有点按斜率排序,从大到小遍历扫描。
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#define ll long long#define INF 1e9+10#define MAXN 305using namespace std;int n;struct node{ double x; double y; double k; ll v;}a[50005],b[50005];int ca;int cb;bool cmp(node f,node g){ return f.k>g.k;}int main(){ int t; scanf("%d",&t); for(int w=1;w<=t;w++) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); ca=0;cb=0; scanf("%d",&n); double x,y; ll z; ll sum1=0; ll sum2=0; for(int i=0;i<n;i++) { scanf("%lf%lf%lld",&x,&y,&z); if(x<0||(x==0&&y<0)) { b[cb].x=x; b[cb].y=y; b[cb].v=z; if(x==0&&y<0) b[cb].k=INF; else if(x==0&&y>0) b[cb].k=INF; else b[cb].k=y/x; sum2+=z; cb++; } else { a[ca].x=x; a[ca].y=y; a[ca].v=z; if(x==0&&y<0) a[ca].k=INF; else if(x==0&&y>0) a[ca].k=INF; else a[ca].k=y/x; sum1+=z; ca++; } } ll ans; ans=sum1*sum2; sort(a,a+ca,cmp); sort(b,b+cb,cmp); int h=0; int l=0; while(1) { if((l==cb||a[h].k>b[l].k)&&h<ca) { sum1-=a[h].v; sum2+=a[h].v; h++; } else if((h==ca||a[h].k<b[l].k)&&l<cb) { sum1+=b[l].v; sum2-=b[l].v; l++; } //cout<<l<<" "<<h<<endl; ans=max(ans,sum1*sum2); if(l>=cb&&h>=ca) break; } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- 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 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
- 23种设计模式
- BZOJ4596 黑暗前的幻想乡 Matrix_Tree定理 容斥原理
- 【矩阵快速幂模板】
- 关于ANR和Force Close
- 背包之01背包、完全背包、多重背包详解
- HDU 6127 Hard challenge(几何)
- Java对浮点型数据保留小数点后n位
- pandas入门——数据合并merge函数
- 网易面试题 两种排序方法
- Namespace declaration statement has to be the very first statement in the script
- [资源分享]一个类似我的世界的UNITY分享
- 递归
- Linux系统学习方法——写给小白
- JZOJ1333. H函数 (2017.8B组)