bzoj 1199 二分暴力
来源:互联网 发布:hbuilder for mac下载 编辑:程序博客网 时间:2024/04/24 11:04
这道题的数据范围是25W...
直接暴力。。。
将所有点按照x排序之后。遍历所有的矩形和圆,用upper_bound和lower_bound寻找出符合图形x坐标的所有点,(位于区间[s,t]),然后暴力枚举刚才寻找的点判断是否在当前形状内。。
好黄好暴力。upper_bound和lower_bound的新用法~~
#include <algorithm>#include <algorithm>#include <iostream>#include<string.h>#include <fstream>#include <math.h>#include <vector>#include <cstdio>#include <string>#include <queue>#include <stack>#include <map>#include <set>#define exp 1e-8#define fi first#define se second#define ll long long#define INF 0x3f3f3f3f#define lson l,mid,rt<<1#define pb(a) push_back(a)#define mp(a,b) make_pair(a,b)#define rson mid+1,r,(rt<<1)+1#define all(a) a.begin(),a.end()#define mm(a,b) memset(a,b,sizeof(a));#define for1(a,b) for(int a=1;a<=b;a++)//1---(b)#define rep(a,b,c) for(int a=b;a<=c;a++)//b---c#define repp(a,b,c)for(int a=b;a>=c;a--)///using namespace std;void bug(string m="here"){cout<<m<<endl;}template<typename __ll> inline void READ(__ll &m){__ll x=0,f=1;char ch=getchar();while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}m=x*f;}template<typename __ll>inline void read(__ll &m){READ(m);}template<typename __ll>inline void read(__ll &m,__ll &a){READ(m);READ(a);}template<typename __ll>inline void read(__ll &m,__ll &a,__ll &b){READ(m);READ(a);READ(b);}template<typename __ll>inline void read(__ll &m,__ll &a,__ll &b,__ll &c){READ(m);READ(a);READ(b);READ(c);}template < class T > T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template < class T > T lcm(T a, T b) { return a / gcd(a, b) * b; }template < class T > inline void rmin(T &a, const T &b) { if(a > b) a = b; }template < class T > inline void rmax(T &a, const T &b) { if(a < b) a = b; }template < class T > T pow(T a, T b) { T r = 1; while(b > 0) { if(b & 1) r = r * a; a = a * a; b /= 2; } return r; }template < class T > T pow(T a, T b, T mod) { T r = 1; while(b > 0) { if(b & 1) r = r * a % mod; a = a * a % mod; b /= 2; } return r; }const int maxn=250000+100;int ans[maxn];struct POINT{ double x,y;int idx; bool operator <(const POINT &a)const { return x<a.x; } POINT(){} POINT(double a,double b) { x=a,y=b; }}point[maxn];int cnt_point=0;struct square{ POINT p1,p2; void read() { scanf("%lf %lf %lf %lf",&p1.x,&p1.y,&p2.x,&p2.y); } bool insize(POINT tmp) { if(tmp.x>p1.x&&tmp.x<p2.x&&tmp.y>p1.y&&tmp.y<p2.y) return 1; return 0; } void cal() { int s=upper_bound(point,point+cnt_point,p1)-point; int t=lower_bound(point,point+cnt_point,p2)-point-1; for(int i=s;i<=t;i++) if(insize(point[i])) ans[point[i].idx]++; }}squ[maxn];int cnt_squ=0;struct circle{ POINT p; double r; void read() { scanf("%lf %lf %lf",&p.x,&p.y,&r); } double dist(POINT tmp) { return (tmp.x-p.x)*(tmp.x-p.x)+(tmp.y-p.y)*(tmp.y-p.y); } bool insize(POINT tmp) { if(dist(tmp)<r*r) return 1; return 0; } void cal() { int s=upper_bound(point,point+cnt_point,POINT(p.x-r,0.0))-point; int t=lower_bound(point,point+cnt_point,POINT(p.x+r,0.0))-point-1; for(int i=s;i<=t;i++) if(insize(point[i])) ans[point[i].idx]++; }}cir[maxn];int cnt_cir=0;int main(){ int n,m; read(n,m); cnt_point=m; char ch[200]; while(n--) { scanf("%s",ch); if(ch[0]=='r') squ[cnt_squ++].read(); else cir[cnt_cir++].read(); } rep(i,0,m-1)scanf("%lf %lf",&point[i].x,&point[i].y),point[i].idx=i; sort(point,point+m); rep(i,0,cnt_squ-1)squ[i].cal(); rep(i,0,cnt_cir-1)cir[i].cal(); rep(i,0,m-1)printf("%d\n",ans[i]); return 0;}
0 0
- bzoj 1199 二分暴力
- BZOJ 1046: [HAOI2007]上升序列 暴力,二分
- 二分+暴力
- 暴力进阶,有序二分暴力
- BZOJ 3181: [Coci2012]BROJ 【数据分治(暴力+(二分&&容斥))
- Maximum Value二分二分 暴力暴力
- BZOJ 4352: Tower|暴力
- bzoj 3916 暴力+hash
- poj 2785 二分暴力
- LightOJ 1307【暴力 二分】
- BZOJ 1199 HNOI2005 汤姆的游戏 计算几何+暴力
- BZOJ 2120 数颜色 暴力
- bzoj 1024 生日快乐 暴力搜索
- BZOJ 3045 电话线路 暴力
- BZOJ 3251 树上三角形 暴力
- BZOJ 1024: [SCOI2009]生日快乐|暴力
- BZOJ 3713: [PA2014]Iloczyn|暴力
- 【bzoj 3190】: [JLOI2013]赛车 暴力
- 关于android中broadcast和BroadcastReceiver浅谈
- [LeetCode] Populating Next Right Pointers in Each Node II
- Linux之debugfs介绍
- POJ 2528 Mayor's posters (线段树+离散化)
- ADNROID XML图像资源文件详细讲解(五)
- bzoj 1199 二分暴力
- 将 res 资源文件转换成 file
- C/C++语言 void 及 void 指针深层探索
- ftp上传图片的简单用法
- aapt简介及常用命令
- 简单实现类似Spring的在任意代码中获取Request的功能
- Javadoc导出java类的文档结构小结
- Watson之心:DeepQA
- HDU 5372 Segment Game(2015 Multi-University Training Contest 7 1004)