标签:each bsp pre mode sum string name include while
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1305 Accepted Submission(s): 557
/* * @Author: lyuc * @Date: 2017-08-15 15:31:46 * @Last Modified by: lyuc * @Last Modified time: 2017-08-17 09:01:32 */ /* 题意:给你n个点,每个点都有权值,并且每两个点之间都有一条线,这条线的权值就是端点的权值之积,问你从过原点画一条直线, 使得穿过直线的权值之和最大 思路:这里有一个推论,假如有四个已经按照极角排好序的点,a,b,c,d 有条直线在 b c之间,那么两两之间直线权值和为: ac+ad+bc+bd=a*(c+d)+b*(c+d)=(a+b)*(c+d); 这样题目就出来了,首先将所有的点按照极角排序,然后遍历所有的点 ,比较得到的每个点 */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> #define LL long long #define INF 0x3f3f3f3f #define pi acos(-1.0) #define MAXN 50005 using namespace std; struct Point{ int x,y; LL val; double cur; }point[MAXN]; int t,n; LL lres,rres; LL res; inline bool cmp(Point a,Point b){ return a.cur<b.cur; } inline void init(){ lres=0; rres=0; res=0; } int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%d",&t); while(t--){ init(); scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d%lld",&point[i].x,&point[i].y,&point[i].val); if(point[i].x==0){//如果在y轴 if(point[i].y>=0) point[i].cur=pi/2; else point[i].cur=-pi/2; }else{ point[i].cur=atan(point[i].y*1.0/point[i].x); } if(point[i].x>=0){ rres+=point[i].val; }else{ lres+=point[i].val; } } sort(point,point+n,cmp); res=lres*rres; for(int i=0;i<n;i++){ if(point[i].x>=0){ rres-=point[i].val; lres+=point[i].val; }else{ lres-=point[i].val; rres+=point[i].val; } res=max(res,lres*rres); } printf("%lld\n",res); } return 0; }
标签:each bsp pre mode sum string name include while
原文地址:http://www.cnblogs.com/wuwangchuxin0924/p/7379789.html