HDU 6127 Hard challenge【几何】
来源:互联网 发布:c语言字符串指针传递 编辑:程序博客网 时间:2024/06/04 23:32
Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1153 Accepted Submission(s): 475
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
思路:把n个点(y轴上的点特判一下)的斜率按从小到大的顺序排序,排序后将n个点扫描一遍就好了。(可以理解为从y轴逆时针扫描),这里有一个技巧,直线左边的点可以与右边的任意一点连成线段,所以线段权值之和就可以变成左边点权值之和乘上右边点权值之和。(x1*y1)+(x1*y2)+(x2*y1)+(x2*y2)=(x1+x2)*(y1+y2)。
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<vector>#include<map>#include<set>#include<algorithm>using namespace std;#define ll long long#define ms(a,b) memset(a,b,sizeof(a))const int M=1e5+10;const int MM=2e3+10;const int inf=0x3f3f3f3f;const int mod=1e9+7;;const double eps=1e-8;const double pi=acos(-1.0);int n,m;struct Point{ int x,y; int val; double ang;}point[M];bool cmp(Point p1,Point p2){ return p1.ang>p2.ang;}void solve(){ ll sum1=0,sum2=0; ll ans=0; sort(point,point+n,cmp); for(int i=0;i<n;i++){ if(point[i].x>=0)sum1+=point[i].val; else sum2+=point[i].val; } ans=sum1*sum2; for(int i=0;i<n;i++){ if(point[i].x>=0){ sum1-=point[i].val; sum2+=point[i].val; } else { sum1+=point[i].val; sum2-=point[i].val; } ans=max(ans,sum1*sum2); } printf("%lld\n",ans);}int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d%d",&point[i].x,&point[i].y,&point[i].val); if(point[i].x==0){ if(point[i].y>=0)point[i].ang=pi/2.0; else point[i].ang=-pi/2.0; } else point[i].ang=atan(point[i].y*1.0/point[i].x); } solve(); } 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
- 房贷算法
- mybatis基础知识
- c++实现栈建立,插入,删除
- GYM 101128 C.Canvas Painting【思维+优先队列】
- 20170816
- HDU 6127 Hard challenge【几何】
- 分布式系统事务一致性解决方案
- 中线交易——股票程序化交易模型鉴赏
- 原型设计模式
- 自定义视图的简单应用
- 数据指标 | 移动应用数据分析体系
- Linux指令ps,top
- OpenGL ES着色器语言之变量和数据类型(一)(官方文档第四章)
- JMS消息平台FioranoMQ更新v10.3.0,改进共享HA功能