HDU 6127 Hard challenge

题目链接:HDU 6127

Hard challenge

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1454    Accepted Submission(s): 618


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
 

题意:

5w个点互相连线,保证每个线段都不经过原点,每个点有个val,线段的val就是2个端点的val乘积。现在从原点引一条直线,问经过的线段val和最大是多少。

题目分析:

一条直线必然会把整个图切成2半,每半各一堆点,然后两边相互连线就是经过的线段,然后答案就是两边点val相加后的乘积。所以把点按极角排序,然后扫一遍角度即可。考虑精度问题。我按斜率排的。

//
//  main.cpp
//  Hard challenge
//
//  Created by teddywang on 2017/8/15.
//  Copyright © 2017年 teddywang. All rights reserved.
//

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
long double m_PI= 3.14159265358979323846264338327950288419716939937510582097494459230781;
using namespace std;
typedef long long ll;
int T;
struct node{
    long double angle;
    long double ba;
    ll val;
    int pos;
    ll x,y;
    friend bool operator < (node a,node b)
    {
        ll ax=a.x,ay=a.y,bx=b.x,by=b.y;
        if(a.x<0)
        {
            ax=-ax;
            ay=-ay;
        }
        if(b.x<0)
        {
            bx=-bx;
            by=-by;
        }
        return ay*bx<by*ax;
        
    }
}s[111111];
int n;
ll sum;
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        memset(s,0,sizeof(s));
        sum=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            ll x,y;
            ll val;
            scanf("%lld%lld%lld",&x,&y,&val);
            sum+=val;
            s[i].x=x;s[i].y=y;s[i].val=val;
        }
        sort(s,s+n);
        ll ans=0;
        ll b1=0,b2=0;
        for(int i=0;i<n;i++)
        {
            if(s[i].x<0) b1+=s[i].val;
            else if(s[i].x>0) b2+=s[i].val;
            else if(s[i].y>0) b1+=s[i].val;
            else b2+=s[i].val;
        }
        ans=b1*(b2);
        for(int i=0;i<n;i++)
        {
            if(s[i].x<0)
            {
                b1-=s[i].val;
                b2+=s[i].val;
            }
            else if(s[i].x>0)
            {
                b1+=s[i].val;
                b2-=s[i].val;
            }
            else if(s[i].y>0)
            {
                b1-=s[i].val;
                b2+=s[i].val;
            }
            else
            {
                b1+=s[i].val;
                b2-=s[i].val;
            }
            ans=max(ans,b1*b2);
        }
        printf("%lld\n",ans);
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值