hdu 6127 计算几何模拟题(旋转扫描线)

Hard challenge

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


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


题意:

给出n个点,以及点上的权值,任意两条线可以连线,线上的权值是两个点的权值的乘积

题解:

容易发现,用一条线分割开后,就是两个边的和的乘积了

此时我们用极坐标排序,然后用一条射线进行扫描处理即可

队友的代码,惋惜


#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

#define MAXN 50005
#define LL long long

struct Point
{
    LL x,y;
    int v;
    double rad;
    bool operator < (const Point&rhs) const
    {
        return rad < rhs.rad;
    }
} p[MAXN];

LL sum[MAXN];

bool left(Point a, Point b)
{
    return (LL)a.x*b.y - (LL)a.y*b.x >= 0;
}

int main()
{
    int n,m,T;
    //freopen("in.txt","r",stdin);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%I64d%I64d%d",&p[i].x,&p[i].y,&p[i].v);
            p[i].rad=atan2(p[i].y, p[i].x);
        }
        sort(p,p+n);
        sum[0]=p[0].v;
        for(int i=1;i<n;i++)
            sum[i]=sum[i-1]+p[i].v;

        LL ans=0;
        LL  L=0,R=0,cnt=0;///L为分割点,R为扫描线
        while(L<n)
        {
            if(R==L){
                R=(R+1)%n;
                cnt++;
            }
            while(R!=L&&left(p[L],p[R]))   ///R不等于L并且在180度之内
            {
                R=(R+1)%n;
                cnt++;
            }
            cnt--; ///分隔线旋转,原本在分隔线上的点到了右边,所以要减去

            LL t1,t2;
            int num=L+cnt;
            if(num<n)
            {
                t1=sum[num]-sum[L];
                t2=sum[n-1]-t1;
                ans=max(ans,t1*t2);
            }
            else
            {
                t1=sum[n-1]-sum[L]+sum[num-(n-1)-1];
                t2=sum[n-1]-t1;
                ans=max(ans,t1*t2);
            }
            L++;   ///分隔线旋转
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值