题目链接

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. mybatis-generator 覆盖新增XML

    参考文章:https://www.cnblogs.com/xxoome/p/10068780.html 1.添加依赖(版本1.3.7) plugin> <groupId>org.my ...

  2. C++ 常见术语及解释

    RAII(Resource Acquisition Is Initialization) 资源获取就是初始化 RTTI(Run-time type information) 运行时类型信息 RVO(R ...

  3. Git 分支合并:合并某次提交

    有时只想合并其它分支到某次提交,而不是所有提交. 一 切换到当前分支 首先,在做一次可能有冲突的合并前尽可能保证工作目录是干净的. 如果你有正在做的工作,要么提交到一个临时分支要么储藏它. 这使你可以 ...

  4. [leetcode]23. Merge k Sorted Lists归并k个有序链表

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. I ...

  5. CentOS 7升级Python到3.5后yum出错

    CentOS 7升级Python到3.5后,我跟以前CentOS 6一样,在/usr/bin/python创建了一个指向Python 3的软连接,然后将/usr/bin/yum的顶部的: !/usr/ ...

  6. [JAVA]JAVA章4 Thread Dump如何分析

    一.Thread Dump介绍 1.1什么是Thread Dump? Thread Dump是非常有用的诊断Java应用问题的工具.每一个Java虚拟机都有及时生成所有线程在某一点状态的thread- ...

  7. 使用RabbitMq

    1.配置环境 http://www.cnblogs.com/longlongogo/p/6479424.html 2.安装RabbitMQ https://www.cnblogs.com/longlo ...

  8. 借助Algorithmia网站API:用AI给黑白照片上色,复现记忆中的旧时光

    先看DEMOhttps://demos.algorithmia.com/colorize-photos/ 了解ColorfulImageColorizationhttps://algorithmia. ...

  9. 【java】:Junit

    创建单元测试文件 点击创建测试文件的目录,比如,我要在control目录下添加一个测试类,点击control文件夹 右键->new->other->junit test case 下 ...

  10. String 常用函数

    判断字符串是否包含指定字符str.contains("string"); 查找指定字符索引str.indexOf("s"'); 查找最后出现的字符索引str.i ...