zoukankan      html  css  js  c++  java
  • 2017多校第7场 HDU 6127 Hard challenge 极角排序,双指针

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6127

    题意:平面直角坐标系上有n个整点,第i个点有一个点权val​,坐标为(xi,yi),其中不存在任意两点连成的直线经过原点。这些整点两两之间连有一条线段,线段的权值为其两端点的权值之积。你需要作一条过原点而不过任意一个给定整点的直线,使得和这条直线相交的线段的权值和最大。

    解法:对于一条直线,线段权值和实际上就等于其两边点权和的乘积,所以把所有点按极角排个序,然后扫一圈就好了。

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int maxn=1e5+10;
    const double pi = acos(-1);
    struct node{
        int val;
        double arg;
    }p[maxn];
    bool cmp(node a, node b){
        return a.arg<b.arg;
    }
    LL sum[maxn];
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--){
            int n;
            scanf("%d", &n);
            LL tot=0;
            for(int i=1; i<=n; i++){
                int x,y;
                scanf("%d%d%d",&x,&y,&p[i].val);
                p[i].arg=atan2(y,x);
                tot+=p[i].val;
            }
            sort(p+1,p+n+1,cmp);
            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].val;
            LL ans=0;
            int id = 1;
            for(int i=1; i<=n; i++){
                while(p[id].arg-p[i].arg<pi) id++;
                LL x=sum[id-1]-sum[i-1];
                ans = max(ans, x*(tot-x));
            }
            printf("%lld
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    业务需求、用户需求和功能需求
    乐观锁的两种实现方式
    数据字典
    freemarker(ftl)标签用法
    commons-lang常用方法
    前端与后端分离
    jar包导入本地maven库的操作
    本地打jar包到本地的Maven出库
    MyEclipse中好用的快捷键汇总整理
    简单的反编译class文件并重新编译的方法
  • 原文地址:https://www.cnblogs.com/spfa/p/7367735.html
Copyright © 2011-2022 走看看