首页 > 其他分享 >POJ 2318(点集二分)

POJ 2318(点集二分)

时间:2022-10-25 10:32:33浏览次数:64  
标签:include 2318 int x1 点集 x2 POJ y1 y2


Default



TOYS



Description



在长方形 (x1,y1) (x2,y2) 中有n块板(保证与上下边相交),和m个点。



现给出板和点的位置,求各区域点数、

 


POJ 2318(点集二分)_数据

 




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


每组数据给出各区域点数(最左边区域编号0)


区域编号: 点数


…(区域编号0→n)




请按这个格式输出。


不同组数据间输出一空行。 


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​

Time Limit: 2000MS

 

Memory Limit: 65536K

Total Submissions: 8137

 

Accepted: 3848

直接枚举点超时,

所以枚举中间那块板,二分查找(注意Qsort性质,[1, i-1]  和 [ j+1,n]即为所求范围)

但是由于中间那块板并不“计入点集”,所以 i 和 j 可能 越界,要特判。

由于用int会乘越界(这题没给范围),所以稳妥的用double.



#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define MAXN (5000+10) //Board
#define MAXM (5000+10) //Toy
struct 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;
void binary(int L,int R,int l,int r)
{
if (R-L==1)
{
cout<<L<<": "<<r-l+1<<endl;
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("poj2318.in","r",stdin);
scanf("%d%d",&n,&m);
while (1)
{
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));
for (int i=1;i<=m;i++) cin>>a[i];
binary(0,n+1,1,m);
if (scanf("%d%d",&n,&m)==2) cout<<endl; else break;
}
return 0;
}


标签:include,2318,int,x1,点集,x2,POJ,y1,y2
From: https://blog.51cto.com/u_15724837/5794114

相关文章

  • POJ 1825/2279(Young/Mr. Young's Picture Permutations-杨氏矩阵和钩子公式)
    给出一个n行的矩阵,每一行有a[i]个数,总共有sum个数,要求每一个位置的数必须比上面的数和左面的数大,求总方案数.杨氏矩阵又叫杨氏图表,它是这样一个矩阵,满足条件:(1)如果格子......
  • POJ 1201 Intervals 差分约束
    ​​http://poj.org/problem?id=1201​​TLE了很久,因为用了cin.....思路和其他差分约束差不多,​​http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html​​......
  • DFS练习: POJ1010 POJ1011 POJ1020 POJ1321 POJ1416 POJ1724
    POJ1010packagepoj1010;importjava.util.Arrays;importjava.util.Scanner;/***@Authorjinjun99*@DateCreatedin2022/10/418:11*@Description*@S......
  • DFS练习: POJ2362 POJ2676 POJ2698 POJ3083 POJ3411
    POJ2362packagepoj2362;importjava.util.Scanner;/***@Authorjinjun99*@DateCreatedin2022/10/513:22*@Description*用到了定序剪枝,遍历正方形的......
  • POJ 1389. Area of Simple Polygons 题解
    关于扫描线的介绍可以去看OIWiki。但那上面的参考代码并不好,下面给出了带注释的POJ1389题代码。/**Title:AreaofSimplePolygons*Source:POJ*URL:htt......
  • SPOJ Number of Palindromes(回文树)
    ​​NumberofPalindromes​​TimeLimit: 100MS MemoryLimit: 1572864KB 64bitIOFormat: %lld&%llu​​Submit​​​ ​​Status​​DescriptionEachpalin......
  • POJ-1322 Chocolate(概率DP)
    ChocolateTimeLimit:2000MSMemoryLimit:65536KTotalSubmissions:9279Accepted:2417SpecialJudgeDescriptionIn2100,ACMchocolatewillb......
  • POJ-1276-Cash Machine(多重背包)
    CashMachineTimeLimit:1000MSMemoryLimit:10000KTotalSubmissions:30568Accepted:11018DescriptionABankplanstoinstallamachineforca......
  • POJ 3760. 魔兽世界(修订版) 题解
    一句话,大模拟,照着题意敲就完了。写的期间甚至因为疫情导致程序被锁在了机房www//3760.魔兽世界(修订版)#include<iostream>#include<cstring>#include<string>u......
  • DO、VO、BO、DTO、POJO
    DO:DomainObject 即数据库表字段在Java中一一对应关系(有人称它实体类)BO:BusinessObject即业务对象,Service层向上传传输的对象。是多个DO的组合形式VO:viewoject展示......