HDU 6127 Hard challenge 计算几何 极角排序



Hard challenge

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


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

本题就是要在给定的点和权值的基础上 在坐标系中画一条直线 
然后求这个直线所穿过的边权最大是多少
边权=两边的点权之积求和

仔细想想其实这道题 相当于把坐标系中的点分为两部分 然后对分别把两边的点求和再乘起来
因为 假设 在两边 分别有点权为a1a2和b1b2的点
那么 其边权为a1*b1+ a2*b2 +  a2*b1+a1*b2 = (a1+a2)*(b1*b2)

所以我们 按照极角排序然后遍历求解 一开始用atan2无线wa 
后来改用atan后ac 
所以以后一个不行的时候换换另一个
现在还是不太明白为什么一定要按照极角排序扫 或是一定要按照atan排序扫才能AC
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
const double eps = 1e-9;
typedef long long ll;
int n;
struct node
{
    double x,y;
    int v;
    double ang;
    bool operator<( node &ne)const{
        return ang<ne.ang;
    }
}p[500005];
void solve(){
    sort(p+1,p+1+n);
    ll sumL = 0,sumR=0,ans=0;
    rep(i,1,n)
        if(p[i].x>eps)sumL+=p[i].v;
        else sumR+=p[i].v;
    ans = sumL*sumR;
    rep(i,1,n){
        if(p[i].x>eps)sumL-=p[i].v,sumR+=p[i].v;
        else sumL+=p[i].v,sumR-=p[i].v;
        ans = max(ans,sumL*sumR);
    }
    printf("%lld\n",ans);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        rep(i,1,n)
        {
            scanf("%lf%lf%d",&p[i].x,&p[i].y,&p[i].v);
            p[i].ang = atan2(p[i].y,p[i].x);
        }
        solve();
    }
    return 0;
}


 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值