HDU6127-Hard challenge

Hard challenge

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

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

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
2017 Multi-University Training Contest - Team 7

题目大意: 坐标系中有一些点,从原点画不经过任何点的直线,将点分为两部分,问两部分权的乘积最大为多少。
解题思路:先极角排序,然后从y轴逆时针扫一圈。

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#define PI (acos(-1.0))
using namespace std;
typedef long long LL;
const int MAXN=5e4+50;
const double eps=1e-8;

int dcmp(double x)
{
    if(fabs(x)<eps) return 0;
    return x>0?1:-1;
}

struct node
{
    int x,y,val;
    double theta;
    bool operator <(const node& rhs) const
    {
        return theta<rhs.theta;
    }
}p[MAXN];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].val);
            if(p[i].x==0) p[i].theta=PI/2.0;
            else p[i].theta=atan((double)p[i].y/p[i].x);
        }
        sort(p+1,p+n+1);
        LL rsum=0,lsum=0;
        for(int i=1;i<=n;i++)
        {
            if(p[i].x>=0) rsum+=p[i].val;
            else lsum+=p[i].val;
        }
        LL ans=lsum*rsum;
        for(int i=1;i<=n;i++)
        {
            if(p[i].x>=0) rsum-=p[i].val,lsum+=p[i].val;
            else lsum-=p[i].val,rsum+=p[i].val;
            ans=max(ans,lsum*rsum);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值