Cod sursa(job #25401)

Utilizator magicMaria Ionescu magic Data 4 martie 2007 12:27:39
Problema Ograzi Scor 10
Compilator cpp Status done
Runda preONI 2007, Runda 3, Clasele 11-12 Marime 1.21 kb
#include<iostream>
#include<fstream>

#define inputfile "ograzi.in"
#define outputfile "ograzi.out"

using namespace std;

const int NMAX = 50000;
const int MMAX = 100000;

typedef struct Point {
  int x,y;
};

void ReadData(int &N, int &M, int &W, int &H, Point d[NMAX], Point p[MMAX]) {
  ifstream from(inputfile);
  from>>N>>M>>W>>H;
  int x,y;
  from>>x>>y;
  d[1].x = x; d[1].y = y;
  int minx = x, miny = y, maxx = x, maxy = y;
  for (int i = 2; i<=N; i++) {
    from>>x>>y;
    d[i].x = x;
    d[i].y = y;
    if (minx>x) minx = x;
    if (miny>y) miny = y;
    if (maxx<x) maxx = x;
    if (maxy<y) maxy = y;
  }
  maxx += H;
  maxy += W; 
  int j = 0;
  for (int i = 1; i<=M; i++) {
    from>>x>>y;
    if ( (x>=minx) && (x<=maxx) && (y<=maxy) && (y>=miny) ) {
      p[++j].x = x;
      p[j].y = y; 
    }
  }
  M = j;
}

void Numara(int &N, int &M, int &W, int &H, Point d[NMAX], Point p[MMAX]) {
  int nr = 0;
  for (int i = 1; i<=N; i++) 
    for (int j = 1; j<=M; j++)
      if ( (p[i].x<=d[j].x+W) && (p[i].x>=d[j].x) &&
	   (p[i].y<=d[j].y+H) && (p[i].y>=d[j].y) )
	     nr++;
  ofstream to(outputfile);
  to<<nr;
}

int main() {
  int N,M,W,H;
  Point d[MMAX], p[NMAX];
  ReadData(N,M,W,H,d,p);
  Numara(N,M,W,H,d,p);
}