2017 Multi-University Training Contest 7:Hard challenge
来源:互联网 发布:windows截图工具找不到 编辑:程序博客网 时间:2024/06/05 07:06
Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
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
思路:很明显当2边的点的价值和越相近,答案的值越大。求出每个点的极角,把极角为负值的加上PI=3.1415926,并把这个点标记一下是在x轴上面,还是x轴下面。然后对极角进行排序。然后从x轴开始用直线扫一边,因为每个点都被转化到x轴上面了,所以就很好处理了。
#include<bits/stdc++.h>using namespace std;const int MAX=5e5+10;const double PI=acos(-1);struct Point{ double x,y; double angle; long long v,tag;}p[MAX];int cmp(const Point& x,const Point& y){return x.angle<=y.angle;}int main(){ int T,n; cin>>T; while(T--) { cin>>n; long long up=0,down=0; for(int i=0;i<n;i++) { scanf("%lf%lf%lld",&p[i].x,&p[i].y,&p[i].v); p[i].angle=atan2(p[i].y,p[i].x); if(p[i].angle<0)p[i].angle+=PI+1e-7; if(p[i].y>=0)up+=p[i].v,p[i].tag=1; else down+=p[i].v,p[i].tag=-1; } sort(p,p+n,cmp); long long ans=up*down; for(int i=0;i<n;i++) { if(p[i].tag==1) { up-=p[i].v; down+=p[i].v; } else { up+=p[i].v; down-=p[i].v; } ans=max(ans,up*down); } cout<<ans<<endl; } return 0;}
阅读全文
1 0
- 2017 Multi-University Training Contest 7:Hard challenge
- HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest
- HDU 6127 Hard challenge (极角排序+二分, 2017 Multi-Univ Training Contest 7)
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- Installation failed with message Failed to establish session.
- 三种不定高的div垂直居中方式
- Spark踩坑记——Spark Streaming+Kafka
- 智捅马蜂窝Comb
- hdu1240 (bfs)
- 2017 Multi-University Training Contest 7:Hard challenge
- 第二章 Xadmin_View
- 2017年5月iOS招人心得答案总结(高级篇)
- 基于k-means和tfidf的文本聚类代码简单实现
- C语言 static和extern关键字 对函数的作用
- PAT乙级 1041.考试座位号(15)
- finalize()方法和System.gc()方法
- HDU1593
- C#学习