bzoj 2732: [HNOI2012]射箭 半平面交
题目大意:
题解:
这道题的做法我不想说什么了。。。
其他题解都有说做法。。。
即使是我上午做的题,晚上写的题解
看到这道题我就感觉到累.
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 210010;
const long double eps = 1e-18;
inline int dcmp(const long double &x){
if(x < eps && x > -eps) return 0;
return x > 0 ? 1 : -1;
}
struct Point{
long double x,y;
Point(){}
Point(const long double &a,const long double &b){
x=a;y=b;
}
};
typedef Point Vector;
Vector operator + (const Vector &a,const Vector &b){
return Vector(a.x+b.x,a.y+b.y);
}
Vector operator - (const Vector &a,const Vector &b){
return Vector(a.x-b.x,a.y-b.y);
}
Vector operator * (const Vector &a,const long double &b){
return Vector(a.x*b,a.y*b);
}
long double cross(const Vector &a,const Vector &b){
return a.x*b.y - a.y*b.x;
}
struct line{
Point p;
Vector v;
long double alpha;
int id;
line(){}
line(const Point &a,const Point &b,int i){
p = a;v = b;id = i;
alpha = atan2(v.y,v.x);
// printf("(%lf,%lf) got %lf\n",v.x,v.y,alpha);
}
};
Point lineInterion(const line &l1,const line &l2){
Vector u = l1.p - l2.p;
long double t = cross(l2.v,u)/cross(l1.v,l2.v);
return l1.p + l1.v*t;
}
bool onLeft(const Point &p,const line &l){
return dcmp(cross(l.v,p-l.p)) >= 0;
}
inline bool cmp(const line &a,const line &b){
return a.alpha < b.alpha;
}
line lines[maxn],q[maxn];
Point p[maxn];
int l,r;
inline bool halfInterion(int n){
l = 1;r = 1;q[1] = lines[1];
for(int i=2;i<=n;++i){
while(l < r && !onLeft(p[r-1],lines[i])) -- r;
while(l < r && !onLeft(p[l],lines[i])) ++ l;
if(dcmp(cross(q[r].v,lines[i].v)) == 0)
q[r] = onLeft(q[r].p,lines[i]) ? q[r] : lines[i];
else q[++r] = lines[i];
if(l < r) p[r-1] = lineInterion(q[r],q[r-1]);
}while(l < r && !onLeft(p[r-1],q[l])) -- r;
return (r-l > 1);
}
line a[maxn];
int n,cnt = 0,tot;
inline bool check(int mid){
tot = 0;
for(int i=1;i<=cnt;++i){
if(a[i].id > mid) break;
tot = i;
lines[i] = a[i];
}
sort(lines+1,lines+tot+1,cmp);
return halfInterion(tot);
}
const long double inf = 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0;
int main(){
read(n);
double v,L,R;
a[++cnt] = line(Point(-inf,-inf),Point(inf,0),0);
a[++cnt] = line(Point(inf,-inf),Point(0,inf),0);
a[++cnt] = line(Point(inf,inf),Point(-inf,0),0);
a[++cnt] = line(Point(-inf,inf),Point(0,-inf),0);
for(int i=1;i<=n;++i){
scanf("%lf%lf%lf",&v,&L,&R);
L -= eps;R += eps;
a[++cnt] = line(Point(0,R/v),Point(-1/v,1),i);
a[++cnt] = line(Point(0,L/v),Point(1/v,-1),i);
}
int l = 1,r = n,ans = 0;
while(l <= r){
int mid = (l+r) >> 1;
if(check(mid)) ans = mid,l = mid+1;
else r = mid-1;
}printf("%d\n",ans);
getchar();getchar();
return 0;
}
。。。 。。。

下面的那个Ac是粘的hzwer的代码...最上面的才是自己A的

bzoj 2732: [HNOI2012]射箭 半平面交的更多相关文章
- bzoj2732: [HNOI2012]射箭 半平面交
这题乍一看与半平面交并没有什么卵联系,然而每个靶子都可以转化为两个半平面. scanf("%lf%lf%lf",&x,&ymin,&ymax); 于是乎就有 ...
- bzoj 2732 射箭 半平面交
2732: [HNOI2012]射箭 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2531 Solved: 848[Submit][Status] ...
- BZOJ 2732: [HNOI2012]射箭
2732: [HNOI2012]射箭 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2532 Solved: 849[Submit][Status] ...
- 洛谷P3222 [HNOI2012]射箭(计算几何,半平面交,双端队列)
洛谷题目传送门 设抛物线方程为\(y=ax^2+bx(a<0,b>0)\),我们想要求出一组\(a,b\)使得它尽可能满足更多的要求.这个显然可以二分答案. 如何check当前的\(mid ...
- bzoj 4445 小凸想跑步 - 半平面交
题目传送门 vjudge的快速通道 bzoj的快速通道 题目大意 问在一个凸多边形内找一个点,连接这个点和所有顶点,使得与0号顶点,1号顶点构成的三角形是最小的概率. 假设点的位置是$(x, y)$, ...
- bzoj 3190 赛车 半平面交
直接写的裸的半平面交,已经有点背不过模板了... 这题卡精度,要用long double ,esp设1e-20... #include<iostream> #include<cstd ...
- BZOJ 4445 [Scoi2015]小凸想跑步:半平面交
传送门 题意 小凸晚上喜欢到操场跑步,今天他跑完两圈之后,他玩起了这样一个游戏. 操场是个凸 $ n $ 边形,$ n $ 个顶点 $ P_i $ 按照逆时针从 $ 0 $ 至 $ n-1 $ 编号. ...
- BZOJ 1137: [POI2009]Wsp 岛屿 半平面交
1137: [POI2009]Wsp 岛屿 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 165 Solved: ...
- BZOJ 1829 [Usaco2010 Mar]starc星际争霸 ——半平面交
发现最终的结果只和$s1$,$s2$,$s3$之间的比例有关. 所以直接令$s3=1$ 然后就变成了两个变量,然后求一次半平面交. 对于每一个询问所属的直线,看看半平面在它的那一侧,或者相交就可以判断 ...
随机推荐
- Objective-C 和 Core Foundation 对象相互转换的内存管理总结
本文转载至 http://blog.csdn.net/allison162004/article/details/38756649 OS允许Objective-C 和 Core Foundation ...
- POJ 2092 Grandpa is Famous【水---找出现第二多的数】
链接: http://poj.org/problem?id=2092 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
- sharding-jdbc从入门到出门(03)
经过端午节这2天对 sharding-jdbc一直怀揣成梦想的去学习,还是有一些没有解决的问题: 上一张图:
- UIApplicationDelegate 各方法回调时机
本篇文章主要介绍一些UIApplicationDelegate中几个常用的回调方法的调用时机.以帮助你判断哪些方法倒底放到哪个回调中去实现. 1. – (void)applicationDidFini ...
- 15.Django添加一个功能模块的步骤(和SpringMVC类比)
这里介绍如何在Django里新建一个模块,这个例子还是最简单的例子 通过浏览器访问 http://localhost:8000/hello/然后返回一个欢迎页 我是做java web出身的,这里用py ...
- 很详细、很移动的Linux makefile 教程
近期在学习Linux下的C编程,买了一本叫<Linux环境下的C编程指南>读到makefile就越看越迷糊,可能是我的理解能不行. 于是google到了以下这篇文章.通俗易懂.然后把它贴出 ...
- mybatis_1
mybatis-config.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE co ...
- Python 3 mysql 简介安装
Python 3 mysql 简介安装 一.数据库是什么 1. 什么是数据库(DataBase,简称DB) 数据库(database,DB)是指长期存储在计算机内的,有组织,可共享的数据的集合.数据 ...
- noVNC
noNVC基础用法: 1.下载noVNC git clone https://github.com/novnc/noVNC.git 2.编辑qemu.conf配置文件 Vim /etc/libvirt ...
- Spring Cloud之Ribbon与Nginx区别
客户端负载均衡器 在SpringCloud中Ribbon负载均衡客户端,会从eureka注册中心服务器端上获取服务注册信息列表,缓存到本地. 让后在本地实现轮训负载均衡策略. Ribbon与Nginx ...