2017杭电多校第七场1008 Hard challenge(级角排序)HDU 6127

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 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(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 i th 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
  
  
2 2 1 1 1 1 -1 1 3 1 1 1 1 -1 10 -1 0 100
 

Sample Output
  
  
1 1100
 

Source
 

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


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值