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 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(1T5), denoting the number of test cases.
For each test case:
The first line contains a positive integer n(1n5×104).
The next n lines, the ith line contains three integers xi,yi,vali(|xi|,|yi|109,1vali104).
 

Output
For each test case:
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;}




原创粉丝点击