zoukankan      html  css  js  c++  java
  • HDU 6127 Hard challenge(数学)

    Hard challenge(数学)

    2017 Multi-University Training Contest - Team 7

    题目链接

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

    Problem Description
    There are points on the plane, and the th points has a value , and its coordinate is . 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 , denoting the number of test cases.
    For each test case:
    The first line contains a positive integer .
    The next lines, the th line contains three integers .

    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
    2017 Multi-University Training Contest - Team 7

    这里写图片描述

    以x轴为分界线对点进行分区,第一次以x坐标为分区依据。
    对斜率进行排序,依y轴为依据进行扫描。求最大值。

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    typedef long long int ll;
    const int maxx=1e5;
    struct node
    {
        double x,y,value;
    }as[maxx];
    bool cmp(node a,node b)
    {
        return a.x<b.x;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n;
            scanf("%d",&n);
            int xx,yy,cc;
            int ss=0,sss=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d%d%d",&xx,&yy,&cc);
                if(xx==0) as[i].x=yy<0?-1e10:1e10;//如果xx==0 斜率就 0.0
                else
                    as[i].x=yy*1.0/(xx*1.0);//保存斜率
                as[i].y=xx;//保存 Xi
                as[i].value=cc;
                if(xx>=0) ss+=cc;//ss保存的是当Xi>=0时间的value的值的和
                else sss+=cc;//sss保存的是当Xi<0时间的value的值的和
            }
            ll ans=ss*sss;
            sort(as,as+n,cmp);//对斜率排序
            for(int i=0;i<n;i++)//扫描一圈
            {
                if(as[i].y>=0)
                    ss-=as[i].value,sss+=as[i].value;
                else
                    ss+=as[i].value,sss-=as[i].value;
                ans=max(ans,(ll)ss*sss);
            }
            printf("%lld
    ",ans);
        }
    return 0;
    }
  • 相关阅读:
    Scribes:简单而智能的文本编辑器
    [Java 12 IO] IO 总结
    [Java 12 IO] Serializable 初步 ObjectOutputStream ObjectInputStream 将序列化的对象打出来
    IOS数据解析之XML
    IOS数据解析之JSON
    IOS网络请求类(NSURLCollection)
    IOS之多线程
    IOS开发常见注意点
    IOS常用封装总结
    UIScrollView 的常用属性和方法
  • 原文地址:https://www.cnblogs.com/nanfenggu/p/7900052.html
Copyright © 2011-2022 走看看