hdu 6127 Hard challenge(计算几何)
来源:互联网 发布:mac 炉石传说 插件 编辑:程序博客网 时间:2024/05/17 18:17
Hard challenge
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1103 Accepted Submission(s): 457
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
221 1 11 -1 131 1 11 -1 10-1 0 100
Sample Output
11100
解:乘积的和等于和的乘积,首先分成左右两部分,然后遍历所有的点
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<cmath>#include<string>#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N =1e5+10;const int inf = 0x3f3f3f3f;struct node{ LL v; double x, y, deg; bool operator<(const node &A)const { return deg>A.deg; }}p[N], a[N], b[N];int main(){ int t; scanf("%d", &t); while(t--) { int n; scanf("%d", &n); int k1=0, k2=0; LL s1=0, s2=0; for(int i=0;i<n;i++) { scanf("%lf %lf %lld", &p[i].x,&p[i].y,&p[i].v); if(p[i].x<=0) { if(p[i].x==0) { p[i].deg=inf; if(p[i].y<0) p[i].deg=-p[i].deg; } else p[i].deg=p[i].y/p[i].x; a[k1++]=p[i],s1+=p[i].v; } else { p[i].deg=p[i].y/p[i].x; b[k2++]=p[i],s2+=p[i].v; } } sort(a,a+k1); sort(b,b+k2); LL ans=(s1*s2); int l=0; LL s3=s1, s4=s2; for(int i=0;i<k2;i++) { while(l<k1&&a[l].deg>=b[i].deg) { s1-=a[l].v,s2+=a[l].v; ans=max(ans,s1*s2); l++; } s1+=b[i].v,s2-=b[i].v; ans=max(ans,s1*s2); } l=0,s1=s3,s2=s4; for(int i=0;i<k1;i++) { while(l<k2&&b[l].deg>=a[i].deg) { s2-=b[l].v,s1+=b[l].v; ans=max(ans,s1*s2); l++; } s1-=a[i].v,s2+=a[i].v; ans=max(ans,s1*s2); } printf("%lld\n",ans); } return 0;}
阅读全文
0 0
- HDU 6127 Hard challenge【计算几何】
- hdu 6127 Hard challenge(计算几何)
- (计算几何)HDU 6127 Hard challenge
- HDU 6127-Hard challenge(计算几何)
- HDU 6127 Hard challenge(计算几何)
- HDU 6127 Hard challenge (几何)
- HDU 6127 Hard challenge(几何)
- HDU 6127 Hard challenge【几何】
- hdu 6127 Hard challenge (计算几何——斜率排序)
- HDU 6127 Hard challenge 计算几何 极角排序
- HDU 6127 Hard challenge(几何)
- HDU6127 Hard challenge[计算几何]
- HDU6217 Hard challenge(计算几何)
- hdu Hard challenge (几何题)
- HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest
- HDU 6127 Hard challenge(几何 多校第七场)
- HDU 6127 Hard challenge【计算机几何】【思维题】
- HDU 6127 Hard challenge
- node解决异步问题三种方案
- wamp一些mysql配置问题
- 一些经典的常用例子(随时更新)
- tensorflow_api_4:tf.equal( )
- C# gridView 使用右键菜单
- hdu 6127 Hard challenge(计算几何)
- 麻将游戏
- ant用途及简单实现
- 【HDU 2080 】夹角有多大I 【求夹角 acos】
- 特征工程:信息熵、信息增益、信息增益率
- input标签中autocomplete="off"失效的具体解决办法
- KM算法
- PCA主成分分析
- 存储过程(1)----开篇