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 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
 

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;}


 
原创粉丝点击