hard challenge
来源:互联网 发布:cf自慰刷枪源码 编辑:程序博客网 时间:2024/06/07 20:34
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
Hint
题意
n个点 每个点都对应一个val
任两点之间的价值为这两点的值的积
要求找一条从原点出发的直线 求这直线每边任意两个点的价值的积的和最大
题解:
对斜率排序 x为负值的放左边 保证从右边斜率最小开始更新最大值
AC代码
#include<stdio.h>#include<algorithm>using namespace std;typedef long long LL;const int MAXN = 1e5;struct node{ double k; int x,val;}sp[MAXN];bool cmp(node a,node b){ return a.k<b.k;}int main(){ int t; scanf("%d",&t); while (t--){ int n; scanf("%d",&n); int x,y,c; int s1,s2; s1 = s2 = 0; for (int i = 0;i < n; ++i){ scanf("%d%d%d",&x,&y,&c); if (x==0) sp[i].k = (y<0?-1e10:1e10); else sp[i].k = (double)y/(double)x; sp[i].x = x; sp[i].val = c; if (x>=0) s1+=c; else s2+=c; } LL ans = s1*s2; sort(sp,sp+n,cmp); for (int i = 0;i < n; ++i){ if (sp[i].x>=0){ s1-=sp[i].val; s2+=sp[i].val; }else { s1+=sp[i].val; s2-=sp[i].val; } ans = max(ans,(LL)s1*s2); } printf("%lld\n",ans); } return 0;}
- hard challenge
- Hard challenge
- HDU 6127 Hard challenge
- hdu6127 Hard challenge
- hdu 6127 Hard challenge
- HDU6127-Hard challenge
- hdu--6127--Hard challenge
- hdu6127 Hard challenge
- Hard challenge(HDU6127)
- HDU_6127 Hard challenge 【思维】
- HDU 6127 Hard challenge
- HDU6127-Hard challenge
- HDU6127-Hard challenge
- HDU 6127 Hard challenge
- HDU6127-Hard challenge
- hdu 6127 Hard challenge
- HDU6127 Hard challenge【几何】
- HDU 6127 Hard challenge
- 一个简单的语音识别实现---百度在线语音识别REST API SDK(Python)简单使用
- Java动态代理机制
- 设计模式之建造者模式
- 从Spyder3降级回Spyder2
- OpenSceneGraph 笔记–如何导出三角形数据
- hard challenge
- lorawan在嵌入式系统中的实现--节点端(三)--LoraWan 终端移植调试(1)
- textview的长度的不换行
- js 单引号替换成双引号,双引号替换成单引号 操作
- from A import B 和 import A.B 的区别
- 跟我一起写 Makefile (陈皓)
- python3.6 -- 统计当前目录下的数量
- 韩国准备推出全球第一个“机器人税”;顶级人类玩家 Danil Ishutin被AI完败|ServiceHot一周热闻
- Android静态IP设置