hdu 6127 Hard challenge(计算几何)
2017-08-16 16:30
435 查看
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 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
解:乘积的和等于和的乘积,首先分成左右两部分,然后遍历所有的点
#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
, a
, b
;
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;
}
相关文章推荐
- hdu 6127 : Hard challenge (2017 多校第七场 1008)(计算几何)
- (计算几何)HDU 6127 Hard challenge
- HDU 6127 Hard challenge(计算几何)
- hdu 6127 Hard challenge (计算几何——斜率排序)
- HDU 6127 Hard challenge【计算几何】
- HDU 6127-Hard challenge(计算几何)
- HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest - Team 7
- 多校7 HDU-6127 Hard challenge 几何数学,枚举极角
- HDU 6127 Hard challenge(几何)
- HDU 6127 Hard challenge【计算机几何】【思维题】
- HDU 6127 Hard challenge(几何)
- HDU 6127 Hard challenge【几何】
- HDU 2108 Shape of HDU (计算几何)
- HDU 5572 An Easy Physics Problem(计算几何)——2015ACM/ICPC亚洲区上海站-重现赛
- hdu 1174:爆头(计算几何,三维叉积求点到线的距离)
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
- hdu 1077 Catching Fish(计算几何)
- hdu 4741 Save Labman No.004 计算几何
- HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)
- hdu 6055 简单计算几何,查找点的四种办法 2017 Multi-University Training Contest - Team 2