Cod sursa(job #1199736)

Utilizator azkabancont-vechi azkaban Data 20 iunie 2014 14:28:48
Problema Ograzi Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.75 kb
#include <fstream>
using namespace std;
ifstream cin("ograzi.in");
ofstream cout("ograzi.out");
typedef struct celula {
                      long long poz;
                      celula* next; 
                      }*lista;
typedef struct punct {
                      long long x;
                      long long y;
                     };

void add(long long var, lista &p)
{
  lista r= new celula;
  r->poz=var;
  r->next=p;
  p=r;
}   

lista Hash[1000000],r;
punct D[50005];
long long i,n,a,b,m,w,h,sol(0),j,lmax,hmax;
int main()
{
    cin>>n>>m>>w>>h;
    for (i=1;i<=n;++i)cin>>D[i].x>>D[i].y;
    for (i=1;i<=m;++i){
                       cin>>a>>b;
                       add(b,Hash[a]);
                       }
    for (i=1;i<=n;++i) {
                        lmax=w+D[i].x;
                        hmax=h+D[i].y;
                        for (j=D[i].x;j<=lmax;++j)
                                                  {
                                                   r=Hash[j];
                                                   while (r) {
                                                              if ((r->poz<=hmax) && (r->poz>=D[i].y)) {
                                                                                                       ++sol;
                                                                                                       delete r;
                                                                                                       }
                                                              r=r->next;
                                                             }
                                                   }
                        }
    cout<<sol<<"\n";   
return 0;
}