题意:
有若干个点,连成线段,询问从原点引出一条直线,可以穿过的线段,权值和最大是多少
思路:
对于每条线段斜率排序,从y轴开始顺时针旋转,判断左侧与右侧点的权值和,因为要求最大,必然是左侧各个点同右侧各个点都有连线
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
struct node
{
ll x,y,val;
bool friend operator <(node a,node b)
{
node ta=a;
if(a.x<0)
{
ta.x=-a.x;
ta.y=-a.y;
}
node tb=b;
if(b.x<0)
{
tb.x=-b.x;
tb.y=-b.y;
}
return ta.y*tb.x>tb.y*ta.x;
}
}a[500005];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
ll L=0,R=0,ans=0;
for(int i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y>>a[i].val;
if(a[i].x<0 )
L+=a[i].val;
else if(a[i].x>0)
R+=a[i].val;
else if(a[i].y>0)
L+=a[i].val;
else R+=a[i].val;
}
sort(a+1,a+1+n);
ans=L*R;
for(int i=1;i<=n;i++)
{
if(a[i].x>0)
R-=a[i].val,L+=a[i].val;
else if(a[i].x<0)
R+=a[i].val,L-=a[i].val;
else if(a[i].y>0)
L-=a[i].val,R+=a[i].val;
else R-=a[i].val,L+=a[i].val;
ans=max(ans,(ll)L*R);
}
cout<<ans<<endl;
}
}