Hard challenge

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 1487    Accepted Submission(s): 352


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
 

Statistic | Submit | Clarifications | Back

题意:平面上一些点,两点连线的价值等于点的价值的乘积,定义经过原点的一条直线的值等于它所相交的线段的价值的总和。

思路:现对这些点进行极角排序,给直线分为两部分,s1和s2分别表示两部分的价值。设排序后的第一个点(分到左边部分即从第一个点右边一点开始)开始逆时针旋转,离开一个点的时候,s1减去那个点的值,s2加上那个点的值;另设一个变量维护当前的扫描始终是180°。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define ll long long const double pi=acos(-1.0);
const double eps=1e-8; int T;
int n; struct Point{
int x,y;
int val;
double ang;
}point[200000+50]; double angle(Point a){
double x=abs(a.x);
double y=abs(a.y);
if (a.x>0&&a.y>0) return atan(y/x)*180.0/pi;
else if (a.x<0&&a.y>0) return 180.0-atan(y/x)*180.0/pi;
else if (a.x<0&&a.y<0) return 180.0+atan(y/x)*180.0/pi;
else if (a.x>0&&a.y<0) return 360.0-atan(y/x)*180.0/pi;
else if (a.x==0){
if (a.y>0) return 90;
else if (a.y<0) return 270;
else return -1;
}
else if (a.y==0){
if (a.x>0) return 0;
else if (a.x<0) return 180;
else return -1;
}
return -1;
} bool cmp(Point a,Point b){
return a.ang<b.ang;
} int main(){
// freopen("1.txt","r",stdin);
scanf("%d",&T);
while (T--){
scanf("%d",&n);
ll sum=0;
for (int i=1;i<=n;i++){
scanf("%d %d %d",&point[i].x,&point[i].y,&point[i].val);
sum+=point[i].val;
point[i].ang=angle(point[i]);
}
sort(point+1,point+n+1,cmp);
for (int i=n+1;i<=n+n;i++){
point[i]=point[i-n];
point[i].ang+=360;
}
ll s1=0,s2=0;
int r;
for (int i=1;i<=n;i++){
if (point[i].ang-point[1].ang<180){
s1+=point[i].val;
}
else{
r=i;
break;
}
}
s2=sum-s1;
int l=1;
ll ans=0;
while (l<=n){
ans=max(ans,s1*s2);
s1-=point[l].val;
s2+=point[l].val;
l++;
while (r<=2*n&&point[r].ang-point[l].ang<180){
s1+=point[r].val;
s2-=point[r].val;
r++;
}
}
printf("%lld\n",ans);
}
}

最新文章

  1. java web学习总结(二十五) -------------------JSP中的九个内置对象
  2. Second Day: 关于Button监听事件的三种方法(匿名类、外部类、继承接口)
  3. MS AX 技术相关网站收藏
  4. freemodbus-v1.5.0 源码分析
  5. 使用ADO.NET访问数据库
  6. firefox中 checkbox属性checked=&quot;checked&quot;已有,但复选框却不显示打钩的原因
  7. Android在 Alertdialog对话框中点击消失?
  8. set RowCount 与 top n
  9. IPad分屏,当电脑第二显示屏
  10. IPS简单使用方法
  11. 洛谷4451 整数的lqp拆分(生成函数)
  12. linq2db sqlite应用
  13. modifyGeoJSON
  14. Mysq中的流程控制语句的用法
  15. python连接MongoDB(无密码无认证)
  16. [转]Jboss基础
  17. 《汇编语言 基于x86处理器》第十三章高级语言接口部分的代码 part 2
  18. poj 1088 (dfs+记忆化) 滑雪
  19. Jenkins分布式构建
  20. [SHOI2012]回家的路

热门文章

  1. 运算符、流程控制、while循环
  2. poj——3728 The merchant
  3. [HDU5709]Claris Loves Painting(动态开点线段树+合并)
  4. 洛谷 P1065 作业调度方案
  5. win7笔记本如何设置共享网络供手机WIFI上网?
  6. 异 形 卵 709 南阳oj
  7. openTSDB ConnectionManager: Unexpected exception from downstream java.io.IOException: Broken pipe
  8. JSON-JSON字符串转换成JSON对象、JSON对象数组、java实体类以及保存到List列表中
  9. NHibernate之旅(8):巧用组件之依赖对象
  10. 基本数据类型操作的补充和set的基本操作