【极角排序】【扫描线】hdu6127 Hard challenge
平面上n个点,每个点带权,任意两点间都有连线,连线的权值为两端点权值之积。没有两点连线过原点。让你画一条过原点直线,把平面分成两部分,使得直线穿过的连线的权值和最大。
就把点极角排序后,扫过去,一侧的点会跨过直线与另一侧的所有点形成连线。此时的答案为两侧的权值和之积,尝试用此更新最终答案。
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
struct Point{
ll x,y,val;
int xx;
Point(const ll &x,const ll &y){
this->x=x;
this->y=y;
}
Point(const ll &x,const ll &y,const ll &xx){
this->x=x;
this->y=y;
this->xx=xx;
}
Point(){}
void read(){
scanf("%lld%lld%lld",&x,&y,&val);
if(x>0 && y>=0){
xx=1;
}
else if(x<=0 && y>0){
xx=2;
}
else if(x<0 && y<=0){
xx=3;
}
else{
xx=4;
}
}
}p[100005];
bool operator < (const Point &a,const Point &b){
return a.xx!=b.xx ? a.xx<b.xx : a.x*b.y-a.y*b.x>0;
}
ll sum[100005];
int n,T;
int main(){
scanf("%d",&T);
for(;T;--T){
scanf("%d",&n);
for(int i=1;i<=n;++i){
p[i].read();
}
sort(p+1,p+n+1);
for(int i=n+1;i<=2*n;++i){
p[i]=p[i-n];
p[i].xx=p[i-n].xx+4;
}
sum[1]=p[1].val;
for(int i=2;i<=n*2;++i){
sum[i]=p[i].val+sum[i-1];
}
ll ans=0;
int i;
for(i=1;i<=n;++i){
Point *pt=upper_bound(p+1,p+n*2+1,Point(-p[i].x,-p[i].y,p[i].xx+2));
ans=max(ans,(sum[pt-p-1]-sum[i-1])*(sum[n]-sum[pt-p-1]+sum[i-1]));
}
printf("%lld\n",ans);
}
return 0;
}
【极角排序】【扫描线】hdu6127 Hard challenge的更多相关文章
- POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线
从TLE的暴力枚举 到 13313MS的扫描线 再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...
- LA-4356&&hdu-2469 (极角排序+扫描线)
题目链接: Fire-Control System Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)
Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...
- 2017ACM暑期多校联合训练 - Team 7 1008 HDU 6127 Hard challenge (极角排序)
题目链接 Problem Description There are n points on the plane, and the ith points has a value vali, and i ...
- 【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge
acm.hdu.edu.cn/showproblem.php?pid=6127 [题意] 给定平面直角坐标系中的n个点,这n个点每个点都有一个点权 这n个点两两可以连乘一条线段,定义每条线段的权值为线 ...
- poj2280--Amphiphilic Carbon Molecules(扫描线+极角排序+转换坐标)
题目链接:id=2280">点击打开链接 题目大意:给出n个点的坐标.每一个点有一个值0或者1,如今有一个隔板(无限长)去分开着n个点,一側统计0的个数,一側统计1的个数,假设点在板上 ...
- hdu6127 Hard challenge
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6127 题目: Hard challenge Time Limit: 4000/2000 MS ...
- poj2280Amphiphilic Carbon Molecules(极角排序)
链接 卡了几天的破题,对于hdu的那份数据,这就一神题.. 借助极角排序,枚举以每一个点进行极角排序,然后构造两条扫描线,一个上面一个下面,两条同时走,把上线和下线的点以及上线左边的点分别统计出来,如 ...
- POJ 1696 Space Ant 【极角排序】
题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...
随机推荐
- 打开Android系统安装APK的页面
//使用隐式意图开启安装APK的Activity Intent intent = new Intent("android.intent.action.VIEW"); intent. ...
- perl中的默认变量与Z/map介绍
use v6; =begin pod @*ARGS 命令行参数, 不含脚本名 $*PROGRAM-NAME:当前运行脚本的相对路径 $*PROGRAM:当前运行脚本的文件名称 $*CWD:当前工作路径 ...
- 【Python学习笔记】Coursera课程《Python Data Structures》 密歇根大学 Charles Severance——Week6 Tuple课堂笔记
Coursera课程<Python Data Structures> 密歇根大学 Charles Severance Week6 Tuple 10 Tuples 10.1 Tuples A ...
- ktime使用例子【原创】
#include <linux/kernel.h>#include <linux/init.h>#include <linux/module.h>#include ...
- 4.Python3标准库--算法
(一)functools:管理函数的工具 import functools ''' functools模块提供了一些工具来管理或扩展和其他callable对象,从而不必完全重写 ''' 1.修饰符 f ...
- Python——拼接字符串
Python中可以对字符串进行拼接: 1. 使用字符串拼接运算符: + >>> "Hello" + "World" 'HelloWorld' ...
- 查看linux 下进程运行时间(转)
原文地址:http://blog.csdn.net/tspangle/article/details/11731317 可通过ps 来查看,通过参数 -o 来查看 如: ps -eo pid,tty, ...
- Struts2学习笔记03 之 Result组件
二.Result原理 1.stream 2.redirectAction 3.Json
- elasticsearch简单查询
elasticsearch简单查询示例: { "from": "0", //分页,从第一页开始 "size": "10" ...
- ZOJ-3319
Islands Time Limit: 1 Second Memory Limit: 32768 KB There are N islands and some directed paths ...