标签:origin ext blank challenge imu bsp nts hdu ever
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; typedef long long LL; const LL N=5e4+5; const double INF=1e18; struct Node{ LL x,y; LL v; double f; }a[N]; void cal(Node& t) { LL x=t.x; LL y=t.y; if(x==0) t.f=INF; else{ t.f=(double)y*1.0/(double)x; } } LL cmp(const Node s1,const Node s2) { return s1.f<s2.f; } bool check(Node a,Node b) { if(((a.x*b.y-a.y*b.x)*1.0/a.x)>=0.0) return true; return false; } int main() { LL T; cin>>T; while(T--) { LL n; scanf("%lld",&n); LL tot=0; for(LL i=1;i<=n;i++) { scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].v); tot+=a[i].v; cal(a[i]); } if(n==1) { puts("0"); continue; } sort(a+1,a+n+1,cmp); LL ans=0,tmp1=0,tmp2=0; tmp1=a[1].v; for(LL i=2;i<=n;i++) { if(!check(a[1],a[i])) tmp1+=a[i].v; } tmp2=tot-tmp1; ans=max(tmp1*tmp2,ans); if(a[1].x<0) tmp1-=a[1].v; for(LL i=2;i<=n;i++) { if(a[i].x>=0) tmp1+=a[i].v; tmp2=tot-tmp1; ans=max(tmp1*tmp2,ans); if(a[i].x<0) tmp1-=a[i].v; } printf("%lld\n",ans); } return 0; }
标签:origin ext blank challenge imu bsp nts hdu ever
原文地址:http://www.cnblogs.com/chen9510/p/7367878.html