POJ 2398(二分点集)

来源:互联网 发布:safari无痕浏览 知乎 编辑:程序博客网 时间:2024/05/15 20:30
Language:
Toy Storage
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 8137 Accepted: 3848

Description

在长方形 (x1,y1) (x2,y2) 中有n块板(保证与上下边相交),和m个点。
现给出板和点的位置,求拥有相同点数的区域数、
 
 

Input

多组数据.每组数据开头为 n m x1 y1 x2 y2. n (0 < n <= 5000) m (0 < m <= 5000). (x1,y1)为左上角坐标 , (x2,y2)为右下角坐标. 
接下来 n 行有2个数 Ui Li,表示第i块板为 (Ui,y1) (Li,y2). (保证两两不交).
接下来m 行为点的坐标 Xj Yj (保证不在板上)
数据以 0 结束.

Output

每组数据给出同点数的区域数
点数: 区域数
…(点数1→n,区域数为0不输出)

请按这个格式输出。
每组数据开头输出“Box”。 

Sample Input

5 6 0 10 60 03 14 36 810 1015 301 52 12 85 540 107 94 10 0 10 100 020 2040 4060 6080 80 5 1015 1025 1035 1045 1055 1065 1075 1085 1095 100

Sample Output

0: 21: 12: 13: 14: 05: 10: 21: 22: 23: 24: 2

Hint

落在长方形边上的点也算.

Source

Rocky Mountain 2003

基本同POJ 2318


#include<cstdio>#include<cstring>#include<cstdlib>#include<cctype>#include<iostream>#include<algorithm>#include<functional>using namespace std;#define MAXN (1000+10) //Board#define MAXM (1000+10) //Toystruct P{double x,y;P(){}P(int _x,int _y):x(_x),y(_y){}friend istream& operator>>(istream& cin,P &a){cin>>a.x>>a.y;return cin;}}a[MAXM];struct V{double x,y;P s;V(){}V(P a,P b):x(b.x-a.x),y(b.y-a.y),s(a){}friend int operator*(const V a,const V b){return a.x*b.y-a.y*b.x;}}c[MAXN];int n,m,x1,y1,x2,y2,f[MAXM];int cmp(V a,V b){return a.s.x<b.s.x;}void binary(int L,int R,int l,int r){if (R-L==1){f[r-l+1]++;return;}int i=l,j=r,m=(l+r)>>1;V &M=c[(L+R)>>1];do {while (i<=r&&V(M.s,a[i])*M<0) i++;while (j>=l&&V(M.s,a[j])*M>0) j--;if (i<=j) {swap(a[i],a[j]);i++;j--;}}while (i<=j);i--;j++;binary(L,(L+R)>>1,l,i);binary((L+R)>>1,R,j,r);}int main(){//freopen("poj2398.in","r",stdin);while (scanf("%d%d",&n,&m)==2){cout<<"Box\n";memset(f,0,sizeof(f));cin>>x1>>y2>>x2>>y1;for (int i=1;i<=n;i++){int u,l;cin>>u>>l;c[i]=V(P(l,y1),P(u,y2));}c[0]=V(P(x1,y1),P(x1,y2));c[n+1]=V(P(x2,y1),P(x2,y2));sort(c+1,c+1+n,cmp);for (int i=1;i<=m;i++) cin>>a[i];binary(0,n+1,1,m);for (int i=1;i<=m;i++)if (f[i]) cout<<i<<": "<<f[i]<<endl;}return 0;}


原创粉丝点击