POJ 2318 TOYS && POJ 2398 Toy Storage

POJ 2318 TOYS

计算几何+二分

#include
#include
#include
#include
#define maxn 5005 
using namespace std; 

double precision=1e-16;

struct Point{
	int x;
	int y;
};

struct Cardboard{
	Point a;
	Point b;
};
Cardboard card[maxn];
Point p[maxn];
int num[maxn];//用来记录每一个隔断里存了多少个点 

int check(Point a,Point b,Point c){
	int ans=(a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
	if(ans>precision){
		return 1;
	}else{
		return 0;
	}
} 

int erfen(int x,int y,Point p){
	int l=x;
	int r=y-1; 
	while(l<=r){
		int mid=(l+r)/2;
		if(check(card[mid].a,card[mid].b,p)){
			l=mid+1;
		}else{
			r=mid-1;
		}
	} 
	num[l]++;
} 

int main(){
	while(1){
		memset(num,0,sizeof(num));
		int n,m,x1,y1,x2,y2;
		cin>>n;
		if(n==0){
			break;
		}
		else{
			cin>>m>>x1>>y1>>x2>>y2;
			for(int i=0;i>card[i].a.x;
				card[i].a.y=y1;
				cin>>card[i].b.x;
				card[i].b.y=y2;
			}	
			for(int i=0;i>p[i].x;
				cin>>p[i].y;
				erfen(0,n,p[i]);
			}
			for(int i=0;i<=n;i++){
				cout<

POJ 2398 Toy Storage

计算几何+二分+结构体排序

与上一题类似,只不过是对输出方式做一点改变

#include
#include
#include
#include
#define maxn 5005 
using namespace std; 

double precision=1e-16;

struct Point{
	int x;
	int y;
};

struct Cardboard{
	Point a;
	Point b;
};
Cardboard card[maxn];
Point p[maxn];
int num[maxn];//用来记录每一个隔断里存了多少个点 
int Num[maxn];//用来记录存了这个点的隔断有多少个 

int cmp1(Cardboard A,Cardboard B){
	if(A.a.xprecision){
		return 1;
	}else{
		return 0;
	}
} 

int erfen(int x,int y,Point p){
	int l=x;
	int r=y-1; 
	while(l<=r){
		int mid=(l+r)/2;
		if(check(card[mid].a,card[mid].b,p)){
			l=mid+1;
		}else{
			r=mid-1;
		}
	} 
	num[l]++;
} 

int main(){
	while(1){
		memset(num,0,sizeof(num));
		memset(Num,0,sizeof(Num));
		int n,m,x1,y1,x2,y2;
		cin>>n;
		if(n==0){
			break;
		}
		else{
			cin>>m>>x1>>y1>>x2>>y2;
			for(int i=0;i>card[i].a.x;
				card[i].a.y=y1;
				cin>>card[i].b.x;
				card[i].b.y=y2;
			}	
			sort(card,card+n,cmp1);
			sort(card,card+n,cmp2);
			for(int i=0;i>p[i].x;
				cin>>p[i].y;
				erfen(0,n,p[i]);
			}
			
			for(int i=0;i<=n;i++){
				if(num[i]!=0){
					Num[num[i]]++;
				}
			}
			cout<<"Box"<

 

你可能感兴趣的:(计算几何)