hdu 6127 Hard challenge(计算几何)

来源:互联网 发布:mac 炉石传说 插件 编辑:程序博客网 时间:2024/05/17 18:17

Hard challenge

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


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(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 ith 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
221 1 11 -1 131 1 11 -1 10-1 0 100
 

Sample Output
11100

解:乘积的和等于和的乘积,首先分成左右两部分,然后遍历所有的点

#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<cmath>#include<string>#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N =1e5+10;const int inf = 0x3f3f3f3f;struct node{    LL  v;    double x, y, deg;    bool operator<(const node &A)const    {        return deg>A.deg;    }}p[N], a[N], b[N];int main(){    int t;    scanf("%d", &t);    while(t--)    {        int n;        scanf("%d", &n);        int k1=0, k2=0;        LL s1=0, s2=0;        for(int i=0;i<n;i++)        {            scanf("%lf %lf %lld", &p[i].x,&p[i].y,&p[i].v);            if(p[i].x<=0)            {                if(p[i].x==0)                {                    p[i].deg=inf;                    if(p[i].y<0) p[i].deg=-p[i].deg;                }                else p[i].deg=p[i].y/p[i].x;                a[k1++]=p[i],s1+=p[i].v;            }            else            {                p[i].deg=p[i].y/p[i].x;                b[k2++]=p[i],s2+=p[i].v;            }        }        sort(a,a+k1);        sort(b,b+k2);        LL ans=(s1*s2);        int l=0;        LL s3=s1, s4=s2;        for(int i=0;i<k2;i++)        {            while(l<k1&&a[l].deg>=b[i].deg)            {                s1-=a[l].v,s2+=a[l].v;                ans=max(ans,s1*s2);                l++;            }            s1+=b[i].v,s2-=b[i].v;            ans=max(ans,s1*s2);        }        l=0,s1=s3,s2=s4;        for(int i=0;i<k1;i++)        {            while(l<k2&&b[l].deg>=a[i].deg)            {                s2-=b[l].v,s1+=b[l].v;                ans=max(ans,s1*s2);                l++;            }            s1-=a[i].v,s2+=a[i].v;            ans=max(ans,s1*s2);        }        printf("%lld\n",ans);    }    return 0;}





原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 我的手机号被别人绑定了快手怎么办 微信密码忘记了没绑定手机号怎么办 扣扣绑定银行卡忘记密码了怎么办 扣扣忘记密码了又换手机号了怎么办 微信订阅号里有删除后的信息怎么办 申请微信公众号邮箱已被占用怎么办 公众号验证没有对公账户怎么办 qq密码忘记了怎么办手机绑定没有 我的扣扣怎么申诉都找不回来怎么办 装修装的不好又没有签合同怎么办 日本免税的零食不小心拆了怎么办 闲鱼同意买家退货了买家不退怎么办 手机里淘宝钱付了不发货怎么办 百度云下载手机储存空间不足怎么办 苹果8的照片储存空间满了怎么办 为什么下载的软件已停止运行怎么办 苹果手机刷机忘记注册邮箱了怎么办 刺激战场模拟器注册已达上限怎么办 用模拟器玩刺激战场注册上限怎么办 微信解除实名认证后退款怎么办 苹果为什么qq收消息有延迟怎么办 qq忘记密码手机号也换了怎么办 扣扣空间圈人时照片服务错误怎么办 删了qq好友怎么找回来怎么办 苹果5s语音控制打开了怎么办 lv迷你水桶包肩带长了怎么办 在香港买个lv包包过海关怎么办 国际快递手表被海关查应该怎么办 把档案放到人才市场后报到证怎么办 皮表带带久了有异味怎么办 英语中用词不当和拼写错误怎么办 爬楼梯的购物车车轮坏了怎么办? 帮别人买东西不给我钱怎么办 老师念错名字有同学指出来你怎么办 老公婚前买的房子婆婆想霸占怎么办 我想查我的基金收益情况怎么办 儿童票买好了但大人退票了怎么办 没有享受到国家政策的农民怎么办? 股票涨了没抛然后一直跌怎么办 苹果手机放久了开不了机怎么办 部门要辞退你你不想走该怎么办