HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest
来源:互联网 发布:报表软件排名 编辑:程序博客网 时间:2024/05/16 06:30
传送门
Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1093 Accepted Submission(s): 450
Problem Description
There are n points on the plane, and the i th 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 integern(1≤n≤5×104) .
The nextn lines, the i th line contains three integers xi,yi,vali(|xi|,|yi|≤109,1≤vali≤104) .
For each test case:
The first line contains a positive integer
The next
Output
For each test case:
A single line contains a nonnegative integer, denoting the answer.
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
题目大意:
平面直角坐标系上有
解题思路:
经过推导之后会发现:这条经过原点的直线
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int MAXN = 5e4+5;const LL MOD = 1e9+7;struct Point{ LL x, y, v; double ang;}a[MAXN];int cmp(Point A, Point B){ return A.ang < B.ang;}int check(Point A, Point B){//>=0:up <0:down return 1.0*(A.x*B.y-A.y*B.x)*A.x >= 0;}int main(){ //freopen("C:/Users/yaonie/Desktop/in.txt", "r", stdin); //freopen("C:/Users/yaonie/Desktop/out.txt", "w", stdout); int T; scanf("%d",&T); while(T--){ int n; scanf("%d", &n); LL sumv = 0; for(int i=0; i<n; i++){ scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].v); if(a[i].x != 0) a[i].ang = 1.0*a[i].y/a[i].x; else a[i].ang = MOD; sumv += a[i].v; } sort(a, a+n, cmp); LL sum1 = a[0].v, sum2 = 0;//sum1:up sum2:down int cnt = 0; for(int i=1; i<n; i++) if(check(a[0], a[i])) sum1 += a[i].v; sum2 = sumv - sum1; LL ans = sum1*sum2; if(a[0].x > 0) sum1 -= a[0].v; for(int i=1; i<n; i++){ sum2 = sumv - sum1; ans = max(ans, sum1*sum2); if(a[i].x > 0) sum1 -= a[i].v; if(a[i].x < 0) sum1 += a[i].v; sum2 = sumv - sum1; ans = max(ans, sum1*sum2); } printf("%lld\n",ans); } return 0;}
阅读全文
1 0
- HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest
- HDU 6055 Regular polygon(计算几何+思维)——2017 Multi-University Training Contest
- 2017 Multi-University Training Contest 7:Hard challenge
- HDU 6172 Array Challenge(打表+矩阵快速幂)——2017 Multi-University Training Contest
- HDU 6127 Hard challenge (极角排序+二分, 2017 Multi-Univ Training Contest 7)
- 计算几何(组合计数+向量排序)——Eureka ( HDU 5738 ) ( 2016 Multi-University Training Contest 2 1005 )
- hdu 5858 Hard problem(2016 Multi-University Training Contest 10——数学题)
- hdu 5733 tetrahedron(2016 Multi-University Training Contest 1——几何公式题)
- hdu 6055 简单计算几何,查找点的四种办法 2017 Multi-University Training Contest
- hdu 5733 tetrahedron(2016 Multi-University Training Contest 1计算几何)
- 2016 Multi-University Training Contest 1 1011(HDU 5733 计算几何)
- 2016 Multi-University Training Contest 1-1011---HDU 5733 tetrahedron(计算几何)
- HDU 6127 Hard challenge(计算几何)
- hdu 6127 Hard challenge (计算几何——斜率排序)
- hdu 5742 It's All In The Mind(2016 Multi-University Training Contest 2——思维题)
- hdu 5744 Keep On Movin(2016 Multi-University Training Contest 2——回文串,思维题)
- HDU 5860 Death Sequence (递推 + 约瑟夫环 + 思维)——2016 Multi-University Training Contest 10
- (HDU 5738) <计算几何 ,在n个点中找所有共线的集合> 2016 Multi-University Training Contest 2
- xstream
- 谈谈对Spring IOC的理解
- EJB到底是什么??
- Dedecms5.7数据结构说明文档
- Python闭包函数和一些BIF
- HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest
- 扩展阅读 健康身体与强健体魄
- maven项目导入eclipse 后需要做哪些工作?
- 线段树&树状数组&扫描线
- 新手学JsonObject
- 51Nod 1459:迷宫游戏
- nginx---root 与 alias区别
- 使用maven创建web3.0项目
- MyISAM和InnoDB的区别