Cod sursa(job #32719)

Utilizator mugurelionutMugurel-Ionut Andreica mugurelionut Data 18 martie 2007 13:26:33
Problema Ograzi Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.66 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
using namespace std;

#define nmax 50010

int n,m,x[nmax],y[nmax],i,w,h,ex,ey,ux,uy,sol;
char s[128];
double xx,yy;

struct ppp
{
    int x,y;
};

ppp aux;

map<ppp,int> hash;

bool operator < (const ppp &A, const ppp &B)
{
    if (A.x != B.x)
        return A.x < B.x;
    return A.y < B.y;
}

int main()
{
    freopen("ograzi.in","r",stdin);
    freopen("ograzi.out","w",stdout);

    gets(s);
    sscanf(s,"%d%d%d%d",&n,&m,&w,&h);
    for (i=0;i<n;i++)
    {
        gets(s);
        sscanf(s,"%lf%lf",&xx,&yy);
        x[i]=xx,y[i]=yy;
        xx=(xx-0.5)/w+1;
        yy=(yy-0.5)/h+1;
        aux.x=xx,aux.y=yy;
        hash[aux]=i+1;
    }

    for (i=0;i<m;i++)
    {
        gets(s);
        sscanf(s,"%lf%lf",&xx,&yy);
        ux=xx,uy=yy;
        xx-=0.5,yy-=0.5,xx/=w,yy/=w;
        ex=xx,ey=yy;
        aux.x=ex,aux.y=ey;
        if ((hash[aux])&&(ux>=x[hash[aux]-1])&&(ux<x[hash[aux]-1]+w)&&(uy>=y[hash[aux]-1])&&(uy<y[hash[aux]-1]+h))
            ++sol;
        ++ex;
        aux.x=ex,aux.y=ey;
        if ((hash[aux])&&(ux>=x[hash[aux]-1])&&(ux<x[hash[aux]-1]+w)&&(uy>=y[hash[aux]-1])&&(uy<y[hash[aux]-1]+h))
            ++sol;
        --ex,++ey;
        aux.x=ex,aux.y=ey;
        if ((hash[aux])&&(ux>=x[hash[aux]-1])&&(ux<x[hash[aux]-1]+w)&&(uy>=y[hash[aux]-1])&&(uy<y[hash[aux]-1]+h))
            ++sol;
        ++ex;
        aux.x=ex,aux.y=ey;
        if ((hash[aux])&&(ux>=x[hash[aux]-1])&&(ux<x[hash[aux]-1]+w)&&(uy>=y[hash[aux]-1])&&(uy<y[hash[aux]-1]+h))
            ++sol;
    }

    printf("%d\n",sol);

    return 0;
}