HDU6127Hard challenge

Hard challenge

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


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
2 2 1 1 1 1 -1 1 3 1 1 1 1 -1 10 -1 0 100
 

 

Sample Output
1 1100
 

 

Source
/*
* @Author: lyuc
* @Date:   2017-08-15 15:31:46
* @Last Modified by:   lyuc
* @Last Modified time: 2017-08-17 09:01:32
*/
/*
 题意:给你n个点,每个点都有权值,并且每两个点之间都有一条线,这条线的权值就是端点的权值之积,问你从过原点画一条直线,    
     使得穿过直线的权值之和最大

 思路:这里有一个推论,假如有四个已经按照极角排好序的点,a,b,c,d 有条直线在 b c之间,那么两两之间直线权值和为:
     ac+ad+bc+bd=a*(c+d)+b*(c+d)=(a+b)*(c+d);  这样题目就出来了,首先将所有的点按照极角排序,然后遍历所有的点
     ,比较得到的每个点
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define LL long long
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define MAXN 50005

using namespace std;

struct Point{
    int x,y;
    LL val;
    double cur;
}point[MAXN];
int t,n;
LL lres,rres;
LL res;

inline bool cmp(Point a,Point b){
    return a.cur<b.cur;
}

inline void init(){
    lres=0;
    rres=0;
    res=0;
}

int main(){ 
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    scanf("%d",&t);
    while(t--){
        init();
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d%d%lld",&point[i].x,&point[i].y,&point[i].val);
            if(point[i].x==0){//如果在y轴
                if(point[i].y>=0)
                    point[i].cur=pi/2;
                else
                    point[i].cur=-pi/2;
            }else{
                point[i].cur=atan(point[i].y*1.0/point[i].x);
            }
            if(point[i].x>=0){
                rres+=point[i].val;
            }else{
                lres+=point[i].val;
            }
        }
        sort(point,point+n,cmp);
        res=lres*rres;
        for(int i=0;i<n;i++){
            if(point[i].x>=0){
                rres-=point[i].val;
                lres+=point[i].val;
            }else{
                lres-=point[i].val;
                rres+=point[i].val;                
            }
            res=max(res,lres*rres);
        }
        printf("%lld\n",res);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/7379789.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值