Cod sursa(job #253773)

Utilizator razyelxrazyelx razyelx Data 6 februarie 2009 12:22:49
Problema Grendizer Scor 20
Compilator cpp Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 1 Marime 0.73 kb
#include <stdio.h>
FILE*in = fopen("grendizer.in","r");
FILE*out= fopen("grendizer.out","w");
long long n,m;

struct coord{ int x,y;} xy[100001];

long long abs(long long x){
    if(x>0) return x;
    return -x;
}

int main(){
    long long i,j,x,y,r,k,c=100000000;

    fscanf(in,"%lld%lld",&n,&m);

    for(i=1;i<=n;++i){
       fscanf(in,"%lld%lld",&x,&y);
       if(abs(x) <= c && abs(y)<=c){xy[i].x=x;xy[i].y=y;}
       else{--i;--n;}
    }

    for(i=1;i<=m;++i){
       k=0;
       fscanf(in,"%lld%lld%lld",&x,&y,&r);
       if(abs(x)<=c && abs(y)<=c && r<=c*10 && r>0)
	 for(j=1;j<=n;++j){
	    if(abs(x-xy[j].x)+abs(y-xy[j].y) == r)++k;

       }
       fprintf(out,"%lld\n",k);
    }


    return 0;
}