Cod sursa(job #41626)

Utilizator mastermageSchneider Stefan mastermage Data 28 martie 2007 13:58:32
Problema Ograzi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <stdio.h>
#include <algorithm>
#include <map>
//#include <hash_map>
using namespace std;

#define maxN 50100

struct po{int x,y;po(){}po(int const&a,int const&b){x=a;y=b;}bool operator==(po const&r)const{return x==r.x && y==r.y;}bool operator<(po const&r)const{return x<r.x || (x==r.x && y<r.y);}};
typedef pair<po,po> per;

int n,m,w,h,res;
po og[maxN];

void getgr(int&x,int&y){
	x=x-x%w + w;
	y=y-y%h + h;
}

int in(int x,int y, int px, int py){
	return x>=px && y>=py && x<=px+w && y<=py+h;
}

int main(){
	hash_map<int,int> hmp;
	FILE*fi=fopen("ograzi.in","r"),*fo=fopen("ograzi.out","w");
	fscanf(fi,"%d %d %d %d",&n,&m,&w,&h);
	
	map<po,po> mp;
	
	for(int i=0;i<n;i++){
		int x,y,gx,gy;fscanf(fi,"%d %d",&x,&y);og[i]=po(x,y);
		getgr(gx=x,gy=y);
		mp.insert(per(po(gx,gy),po(x,y)));
		
			
	}
	
	
	for(int i=0;i<m;i++){
		int cx,cy,gx,gy;fscanf(fi,"%d %d",&cx,&cy);
		map<po,po>::iterator it;
		getgr(gx=cx,gy=cy);
		
		it=mp.find(po(gx,gy));
		if(it!=mp.end()){
			int x=it->second.x,y=it->second.y;
			if(in(cx,cy,x,y)){res++;continue;}
		}
		
		gx-=w;
		it=mp.find(po(gx,gy));
		if(it!=mp.end()){
			int x=it->second.x,y=it->second.y;
			if(in(cx,cy,x,y)){res++;continue;}
		}
		
		gx+=w;gy-=h;
		it=mp.find(po(gx,gy));
		if(it!=mp.end()){
			int x=it->second.x,y=it->second.y;
			if(in(cx,cy,x,y)){res++;continue;}
		}
		
		gx-=w;
		it=mp.find(po(gx,gy));
		if(it!=mp.end()){
			int x=it->second.x,y=it->second.y;
			if(in(cx,cy,x,y)){res++;continue;}
		}
	}
	
	fprintf(fo,"%d",res);fclose(fi);fclose(fo);return 0;
}