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);
}
}

hdu61272017杭电多校第七场1008Hard challenge的更多相关文章

  1. 杭电多校第七场 1010 Sequence(除法分块+矩阵快速幂)

    Sequence Problem Description Let us define a sequence as below f1=A f2=B fn=C*fn-2+D*fn-1+[p/n] Your ...

  2. 杭电多校第七场-J-Sequence

    题目描述 Let us define a sequence as belowYour job is simple, for each task, you should output Fn module ...

  3. 2017杭电多校第七场1011Kolakoski

    Kolakoski Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Tota ...

  4. 2017杭电多校第七场1005Euler theorem

    Euler theorem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

  5. 2019杭电多校第七场 HDU - 6656 Kejin Player——概率&&期望

    题意 总共有 $n$ 层楼,在第 $i$ 层花费 $a_i$ 的代价,有 $pi$ 的概率到 $i+1$ 层,否则到 $x_i$($x_i \leq 1$) 层.接下来有 $q$ 次询问,每次询问 $ ...

  6. 【杭电多校第七场】A + B = C

    原题: Given a,b,c, find an arbitrary set of x,y,z such that a*10^x+b*10^y=c*10^z and 0≤x,y,z≤10^6. 给你三 ...

  7. [2019杭电多校第七场][hdu6656]Kejin Player

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意为从i级花费a元有p的概率升到i+1级,有1-p的概率降到x级(x<i),查询从L级升 ...

  8. [2019杭电多校第七场][hdu6655]Just Repeat

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 题意是说两个人都有一些带有颜色的牌,两人轮流出牌,但是不能出对面出过的颜色的牌,最后谁不能出牌谁 ...

  9. [2019杭电多校第七场][hdu6651]Final Exam

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6651 题意:n个科目,总共m分,通过一科需要复习花费科目分数+1分钟,在不知道科目分数的情况下,问最少 ...

随机推荐

  1. codeforces 361A

    //这题看着吓人,为何这么水 #include<stdio.h> int main() {  int n,m,i,j;  while(scanf("%d%d",& ...

  2. redis可视化界面的操作【二十一】

    1.安装  2.linux服务器中开启linux服务 root@qiaozhi:~# cd /usr/local/redis root@qiaozhi:/usr/local/redis# ./bin/ ...

  3. Free Goodies UVA - 12260

    Petra and Jan have just received a box full of free goodies, and want to divide the goodies between ...

  4. [bzoj4994][Usaco2017 Feb]Why Did the Cow Cross the Road III_树状数组

    Why Did the Cow Cross the Road III bzoj-4994 Usaco-2017 Feb 题目大意:给定一个长度为$2n$的序列,$1$~$n$个出现过两次,$i$第一次 ...

  5. HDU——2063 过山车

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  6. Restful 级别划分以及HATEOAS是什么?

    Restful简介 Rest是一种软件架构风格.设计风格,而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存 ...

  7. AHCI IDE

    AHCI模式性能好 IDE模式,提高约20%,使用Windows 7 系统,AHCI 模式是最佳选择,特别是对SSD硬盘IDE是为XP的兼容性,RAID 模式是要有两块以上硬盘才能实现AHCI模式装的 ...

  8. 【cocos2d-x 3.7 飞机大战】 决战南海I (三) 敌机实现

    如今来实现敌机类 敌机和我方飞机相似,具有生命值.能够发射子弹.而且有自己的运动轨迹.事实上能够为它们设计一个共同的基类,这样能够更方便扩展. 不同的敌机,应设置不同的标识.属性 // 敌机生命值 c ...

  9. Cracking the Coding Interview 150题(一)

    1.数组与字符串 1.1 实现一个算法,确定一个字符串的所有字符是否全都不同.假设不允许使用额外的数据结构,又该如何处理? 1.2 用C或C++实现void reverse(char* str)函数, ...

  10. 用py文件调用操作系统的命名,粘包问题

    帅爆太阳的男人 1,执行代码 在py代码中去调用操作系统的命令 新的模块:subprocess, import subprocess r = subprocess().Popen( "dir ...