Cod sursa(job #25319)

Utilizator szakiold name szaki Data 4 martie 2007 11:57:28
Problema Ograzi Scor 30
Compilator cpp Status done
Runda preONI 2007, Runda 3, Clasele 11-12 Marime 2.58 kb
/*#include "stdafx.h"
#include "infoarena.h"

#include <conio.h>/**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <map>
#include <set>
using namespace std;

#define _OGRAZI_
#ifdef _OGRAZI_

#ifndef _INC_CONIO
void clrscr()
{
    freopen("ograzi.out", "w", stdout);
}
void getch() {}
#else
void clrscr() {}
#endif

#define rep(i,n) for(i=0;i<n;i++)
#define min(a,b) (((a) < (b)) ? (a) : (b))

typedef pair<int, int> Coord;
typedef map<int, Coord> YMap;
typedef map<int, YMap> XYMap;

XYMap a;

int main()
{
    int n,m,w,h;
    int i;
    int count=0;
    char buf[100];
    memset(buf, 0, sizeof(buf));
    clrscr();
    FILE *fin = fopen("ograzi.in", "r");
    fscanf(fin, "%d %d %d %d\n",&n,&m,&w,&h);
    rep(i, n)
    {
        int x = 0, y = 0, i;
        fgets(buf, '\n', fin);
        for(i = 0; isdigit(buf[i]); i++)
        {
            x *= 10; x+= buf[i] - '0';
        }
        for(++i; isdigit(buf[i]); i++)
        {
            y *= 10; y+= buf[i] - '0';
        }
        int xh = x / w, yh = y / h;
        a[xh][yh] = Coord(x,y);
    }

    rep(i, m)
    {
        int x = 0, y = 0, i;
        XYMap::iterator ix;
        YMap::iterator iy;
        fgets(buf, '\n', fin);
        for(i = 0; isdigit(buf[i]); i++)
        {
            x *= 10; x+= buf[i] - '0';
        }
        for(++i; isdigit(buf[i]); i++)
        {
            y *= 10; y+= buf[i] - '0';
        }
        int xh = x / w, yh = y / h;
        ix = a.find(xh);
        if (ix != a.end())
        {
            iy = ix->second.find(yh);
            if (iy != ix->second.end() && iy->second.first <= x && iy->second.second <= y)
            {
                count++;
                continue;
            }
            iy = ix->second.find(yh-1);
            if (iy != ix->second.end() && iy->second.first <= x && iy->second.second >= y - h)
            {
                count++;
                continue;
            }
        }
        ix = a.find(xh-1);
        if (ix != a.end())
        {
            iy = ix->second.find(yh);
            if (iy != ix->second.end() && iy->second.first >= x-w && iy->second.second <= y)
            {
                count++;
                continue;
            }
            iy = ix->second.find(yh-1);
            if (iy != ix->second.end() && iy->second.first >= x-w && iy->second.second >= y - h)
            {
                count++;
                continue;
            }
        }
    }

    printf("%d", count);
    getch();
    return 0;
}

#endif