题目链接

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 个点,每个点有个权值,点与点之间可以连成线段,线段的权值就是两个端点的权值乘积。任意两个点与原点不可能在一条直线上,求一条直线穿过的线段的最大权值和?
 
思路:我们可以想到,有一条过原点的直线,那么直线穿过的线段都是由直线两侧的点互相连线组成的线段,进一步发现线段的权值和就是两侧的点权值和的乘积。有了前面的简化,我们可以对所有的点按照斜率进行排序,从最小斜率的点开始遍历计算,每次以过当前点的原点的直线为直线,那么我们需要计算两侧点权值和的乘积,那么复杂度是O(n*n)。我们可以优化:第一次以O(n) 遍历计算直线两侧的权值和,那么紧接着的下一次的直线划分的上下两侧只有上次的那个点不同,所以只需要O(1)的考虑上次直线上的那么点是应该加入上侧还是下侧。 所以这部分的做法是O(n) 的,但因为斜率排序是O(n*logn)的,所以整体的复杂度是
O(n*logn)的。
 
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const LL N=5e4+;
const double INF=1e18;
struct Node{
LL x,y;
LL v;
double f;
}a[N]; void cal(Node& t)
{
LL x=t.x;
LL y=t.y;
if(x==) t.f=INF;
else{
t.f=(double)y*1.0/(double)x;
}
}
LL cmp(const Node s1,const Node s2)
{
return s1.f<s2.f;
}
bool check(Node a,Node b)
{
if(((a.x*b.y-a.y*b.x)*1.0/a.x)>=0.0)
return true;
return false;
} int main()
{
LL T; cin>>T;
while(T--)
{
LL n; scanf("%lld",&n);
LL tot=;
for(LL i=;i<=n;i++)
{
scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].v);
tot+=a[i].v;
cal(a[i]);
}
if(n==) { puts(""); continue; }
sort(a+,a+n+,cmp);
LL ans=,tmp1=,tmp2=;
tmp1=a[].v;
for(LL i=;i<=n;i++)
{
if(!check(a[],a[i]))
tmp1+=a[i].v;
}
tmp2=tot-tmp1;
ans=max(tmp1*tmp2,ans);
if(a[].x<) tmp1-=a[].v;
for(LL i=;i<=n;i++)
{
if(a[i].x>=) tmp1+=a[i].v;
tmp2=tot-tmp1;
ans=max(tmp1*tmp2,ans);
if(a[i].x<) tmp1-=a[i].v;
}
printf("%lld\n",ans);
}
return ;
}

hdu 6127---Hard challenge(思维)的更多相关文章

  1. HDU 6127 Hard challenge(扫描线)

    http://acm.hdu.edu.cn/showproblem.php?pid=6127 题意: 有n个点,每个点有一个$(x,y)$坐标和一个权值,任意两点之间都有连线,并且连线的权值为两个顶点 ...

  2. 2017多校第7场 HDU 6127 Hard challenge 极角排序,双指针

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6127 题意:平面直角坐标系上有n个整点,第i个点有一个点权val​,坐标为(xi,yi),其中不存在任 ...

  3. 【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge

    acm.hdu.edu.cn/showproblem.php?pid=6127 [题意] 给定平面直角坐标系中的n个点,这n个点每个点都有一个点权 这n个点两两可以连乘一条线段,定义每条线段的权值为线 ...

  4. hdu 6127 Hard challenge(极角/角度排序+枚举+结构体排序新写法)

    Hard challenge Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

  5. HDU - 6127: Hard challenge(扫描线,atan)

    pro:给定N个二维平面的关键点,保证两点连线不经过原点.现在让你安排一条经过原点,但是不经过关键点的直线,使得两边的和的乘积最大. sol:由于连线不经过原点,所以我们极角排序即可. 具体:因为我们 ...

  6. 2017ACM暑期多校联合训练 - Team 7 1008 HDU 6127 Hard challenge (极角排序)

    题目链接 Problem Description There are n points on the plane, and the ith points has a value vali, and i ...

  7. HDU 6127 Hard challenge (极角扫描)

    题意:给定 n 个点,和权值,他们两两相连,每条边的权值就是他们两个点权值的乘积,任意两点之间的直线不经过原点,让你从原点划一条直线,使得经过的直线的权值和最大. 析:直接进行极角扫描,从水平,然后旋 ...

  8. hdu 6127 : Hard challenge (2017 多校第七场 1008)(计算几何)

    题目链接 题意:二维平面上有n个点(没有重叠,都不在原点,任意两点连线不过原点),每个点有一个权值,用一条过原点的直线把他们划分成两部分,使两部分的权值和的乘积最大.输出最大的乘积. 极角排序后,将原 ...

  9. HDU 6651 Final Exam (思维)

    2019 杭电多校 7 1006 题目链接:HDU 6651 比赛链接:2019 Multi-University Training Contest 7 Problem Description Fin ...

  10. HDU 6038 Function(思维+寻找循环节)

    http://acm.hdu.edu.cn/showproblem.php?pid=6038 题意:给出两个序列,一个是0~n-1的排列a,另一个是0~m-1的排列b,现在求满足的f的个数. 思路: ...

随机推荐

  1. oracle随机数(转)

    1.从表中随机取记录SELECT * FROM (SELECT * FROM STUDENT ORDER BY DBMS_RANDOM.RANDOM) WHERE ROWNUM < 4--表示从 ...

  2. 100-days: seventeen

    Title: How 'Bohemian Rhapsody(波西米亚狂想曲)' ended up in 'Wayne's World(反斗智多星)' and became a phenomenon(现 ...

  3. 100-days: sixteen

    Title: The world's most expensive cities 生活成本最高的城市 For the first time in its 30-year history, the Wo ...

  4. 451. Sort Characters By Frequency将单词中的字母按照从高频到低频的顺序输出

    [抄题]: Given a string, sort it in decreasing order based on the frequency of characters. Example 1: I ...

  5. 【转载】我为什么弃用OpenStack转向VMware vsphere

    我为什么弃用OpenStack转向VMware Vsphere,一切皆为简单.高效.因为我们在工作过程中涉及到大量的测试工作,每天都有成百个虚拟机的创建和销毁工作. 工作任务非常繁重,我们的持续集成平 ...

  6. [leetcode]364. Nested List Weight Sum II嵌套列表加权和II

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

  7. Python开发——文件操作

    文件的读取 http://www.cnblogs.com/linhaifeng/articles/5984922.html

  8. Python开发——面向对象【类、实例】

    类 # class Chinese(object): class Chinese: ''' 类的说明性文档 ''' pass print(Chinese) # <class '__main__. ...

  9. tcp、ip、http

    tcp是传输层协议,ip是网络层协议,http是应用层协议,简单说就是tcp是传输数据,而http是封装数据. rpc与http的区别是项目大的话,接口间调用变多的话,采用rpc的话,不用像http那 ...

  10. URI编码时遇到特殊字符的处理方式

    今天遇到一个问题,在向一个地址发起get请求时,某个参数是这种形式:foo=xx&&yyyy,其中"&&"是参数值的一部分,在调用这个接口时,后台收 ...