hdu6127Hard challenge(极角排序)

Hard challenge

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


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

一些点在平面上,问如何让通过源点的线能经过最多的点点连成的边?
例子:(1,1)=1,(1,-1,)=1两个点在平面上,从原点出发,做垂直他们的连线线段(权值为点点乘积)就有了1。
这一类的题都可看做极角排序题,先对所以的点做极角排序(与x轴的夹角),然后对整个平面的点做与x轴的夹角计算,超过180度的额外计算
+2*PI,最后统计穿过的点点的边权值,计算出最大的的穿过量。

/**
   by z_guibin
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iostream>
#define N 50010
const double PI=acos(-1);
using namespace std;
struct node
{
    int vla;
    double arg;
}p[2*N];
long long sum[2*N];
int cmp(node a,node b)
{
    return a.arg<b.arg;
}
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        long long tot=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            int x,y;
            scanf("%d %d %d",&x,&y,&p[i].vla);
            tot+=p[i].vla;
            p[i].arg=atan2(y,x);
        }
        sort(p+1,p+n+1,cmp);
        long long ans=0;
        for(int i=1;i<=n;i++)
        {
            p[i+n]=p[i];
            p[i+n].arg+=2*PI;
        }

        for(int i=1;i<=2*n;i++)
        {
            sum[i]=sum[i-1]+p[i].vla;
        }

        int st=1;
        for(int i=1;i<=n;i++)
        {
            while(p[st].arg-p[i].arg<PI)
            {
                st++;
            }
            long long x=sum[st-1]-sum[i-1];
            ans=max(ans,x*(tot-x));
        }
        printf("%lld\n",ans);
    }
    return 0;
}

再贴一个额外的代码

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 5e4 + 10;
typedef long long LL;
struct node{
    int v,x,y;
    double o;
}st[MAX];
bool cmp(node i,node j) { return i.o < j.o; }
void solve(int n){
    LL ans = 0,l = 0,r = 0;
    for(int i = 0; i < n; i++)
        if(st[i].x < 0) l += st[i].v;
        else r += st[i].v;
    ans = l * r;
    for(int i = 0; i < n; i++){
        if(st[i].x < 0) r += st[i].v, l -= st[i].v;
        else r -= st[i].v, l += st[i].v;
        ans = max(ans,l * r);
    }
    printf("%lld\n",ans);
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        for(int i = 0; i < n; i++)
            scanf("%d %d %d",&st[i].x,&st[i].y,&st[i].v),st[i].o = 1.0 * st[i].y / st[i].x;
        sort(st,st + n,cmp);
        solve(n);
    }
    return 0;
}
来自http://blog.csdn.net/WYK1823376647/article/details/77236911

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.m或d论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 、1资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值