题目链接

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(1≤T≤5), denoting the number of test cases.

For each test case:

The first line contains a positive integer n(1≤n≤5×104).

The next n lines, the ith line contains three integers xi,yi,vali(|xi|,|yi|≤109,1≤vali≤104).

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

题目描述:

平面上有(n)个点,已知每个点的坐标为((x,y)),以及改点的权值为(val),任意两点之间可以连接成一条不经过原点的边,该边的权值是两个端点的权值的乘积。现在要求画一条经过原点的直线,定义这条直线的权值为这条直线穿过的所有线段的值的和,问权值的最大值。

分析:

对于一条经过原点的直线,一定是把这(n)个点分为了左右两部分,只有连接左右两侧的线段才会对答案有贡献,又因为任意两点之间都有连线,整理后最后的权值就是直线一侧的点的和与另一侧点的和的乘积。现在问题就转化为找到一个最优的划分,使得两侧和的乘积最大。

将n个点按与原点的极角排序,只考虑(180)度的范围,因此按正切值从负无穷到正无穷排序。初始时分界线为(y)轴,横坐标小于(0)的为一部分,横坐标大于(0)的为另一部分,初始答案为这两部分的乘积。按排好的序依次处理每个点,相当于这条分界线在按逆时针转动,如果遇到一个横坐标为正的点,就把它扔到左侧,如果遇到横坐标为负的点,就扔到右侧,每次更新答案,遍历一遍后得到最大得分。

代码:

#include<cmath>
#include<cstdio>
#include<algorithm>
typedef long long ll;
using namespace std;
#define eps 1e-9
#define maxn 200005
struct Node
{
double x,y,ang;///横纵坐标,极角
int v;///权值
} p[maxn]; bool cmp(Node a,Node b)///结构体按照极角从小到大排序
{
return a.ang<b.ang;
}
int n,T;
ll sumL,sumR,ans;
void work()
{
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%lf%lf%d",&p[i].x,&p[i].y,&p[i].v);
p[i].ang=atan(p[i].y/p[i].x);
}
sort(p+1,p+n+1,cmp);
sumL=sumR=ans=0;
for(int i=1; i<=n; i++)
if (p[i].x>eps)sumL+=p[i].v;
else sumR+=p[i].v;
ans=sumL*sumR;
for(int i=1; i<=n; i++)
{
if (p[i].x>0)sumL-=p[i].v,sumR+=p[i].v;
else sumL+=p[i].v,sumR-=p[i].v;
ans=max(ans,sumL*sumR);
}
printf("%lld\n",ans);
}
int main()
{
scanf("%d",&T);
while (T--)
work();
return 0;
}

2017ACM暑期多校联合训练 - Team 7 1008 HDU 6127 Hard challenge (极角排序)的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)

    题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...

  2. 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)

    题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...

  3. 2017ACM暑期多校联合训练 - Team 2 1008 HDU 6052 To my boyfriend (数学 模拟)

    题目链接 Problem Description Dear Liao I never forget the moment I met with you. You carefully asked me: ...

  4. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  5. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  6. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

  7. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...

  8. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

  9. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

随机推荐

  1. 【BioCode】读文件夹以发现缺失文件

    代码说明: 使用单个蛋白质的txt计算PSSM生成的结果为单个的PSSM文件. 但是由于一些原因(如蛋白质序列过长),会导致一些蛋白质txt文件无法计算出pssm,为了找到这些没有计算出pssm的蛋白 ...

  2. #Leetcode# 922. Sort Array By Parity II

    https://leetcode.com/problems/sort-array-by-parity-ii/ Given an array A of non-negative integers, ha ...

  3. xpath的学习

    xpath的作用就是两个字“定位”,运用各种方法进行快速准确的定位,推荐两个非常有用的的firefox工具:firebug和xpath checker   定位 1.依靠自己属性,文本定位 //td[ ...

  4. 解决pciss_spc导入提示表空间不存在以及扩展失败的问题

    select NAME FROM USER$ ORDER BY NAME ; CREATE USER pciss IDENTIFIED BY pciss ; GRANT DBA TO pciss ; ...

  5. HDU4753 Fishhead’s Little Game——2013 ACM/ICPC Asia Regional Nanjing Online

    今天比赛又是做得好水的.被狂虐啊. 比赛两个多小时一直没出题,遒遒最先交的若干发都wa了.T_T 我独自在一遍苦思了1006这个题,还好最后把这个题目A掉了,不然又是深坑队友. 题目的意思我就不多说了 ...

  6. C++解析(29):类型识别

    0.目录 1.类型识别 2.动态类型识别 3.类型识别关键字 4.小结 1.类型识别 在面向对象中可能出现下面的情况: 基类指针指向子类对象 基类引用成为子类对象的别名 静态类型--变量(对象)自身的 ...

  7. 使用Unity5.1进行VR开发的配置(最新的未必是最好的!!!)

    随着Unity5.1的发布,之前的Oculus Rift和Gear VR 开发流程发生了巨大的变化,这也算是小白鼠们必须付出的代价了~ 那么Unity5.1和Oculus的整合究竟发生了哪些变化,对开 ...

  8. Redis的键值命令、服务器命令

    Redis提供了丰富的命令对数据库和各种数据类型进行操作,这些命令可以在Linux 终端使用.在编程时,比如各类语言包,这些命令都有对应的方法. 键值命令 服务器命令 获取数据库中所有键名 >k ...

  9. 解题:ZJOI 2006 游戏排名系统

    题面 跟i207M学了学重载运算符后找前驱后继,然后就是练练无旋树堆 #include<map> #include<cstdio> #include<string> ...

  10. 前端解放生产力之–动画(Adobe Effects + bodymovin + lottie)

    大概很久很久以前,2017年,参加了第二届中国前端开发者大会(FDCon2017),除了看了一眼尤雨溪,印象最深刻的就是手淘渚薰分享的关于H5交互的内容了.时光荏苒,最近再次接触,简单回顾一下. 示例 ...