Cod sursa(job #541778)

Utilizator SadmannCornigeanu Calin Sadmann Data 25 februarie 2011 14:15:42
Problema Walls Scor 30
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 1 Marime 1.62 kb
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;

typedef struct zid
{
    int lat;
    int h;
    int x;
};
zid v[100001];
vector<int> lovit[100001];
int n,m,Gx,Gy,i,j;
FILE *in,*out;


int main()
{
    in=fopen("walls.in","rt");
    out=fopen("walls.out","wt");
    fscanf(in,"%d",&n);
    fscanf(in,"%d %d",&v[1].lat,&v[1].h);
    v[1].x=1;
    int maxh=0;
    for(i=2;i<=n;i++)
    {
        fscanf(in,"%d %d",&v[i].lat,&v[i].h);
        v[i].x=v[i-1].x+v[i-1].lat+1;
        if(maxh<v[i].h)
            maxh=v[i].h;
    }
    fscanf(in,"%d",&m);
    for(i=1;i<=m;i++)
    {
        fscanf(in,"%d %d",&Gx,&Gy);
        bool ok=false;
        bool okcazut=false;
        if(Gy<=maxh)
        {
            for(j=n;j>=1;j--)
            {
                if(v[j].h>=Gy && v[j].x<Gx)
                {
                    int cnt;
                    ok=true;
                    fprintf(out,"HIT ");
                    cnt=count(lovit[j].begin(),lovit[j].end(),Gy);

                    if(cnt+1==v[j].lat)
                    {
                        okcazut=true;
                        v[j].h=Gy-1;
                    }
                    lovit[j].push_back(Gy);
                    fprintf(out,"%d %d ",v[j].x+v[j].lat-cnt-1,j);
                    if(!okcazut)
                        fprintf(out,"NO\n");
                    else
                        fprintf(out,"YES\n");
                    break;
                }
            }
        }
        if(!ok)
            fprintf(out,"MISS\n");
    }
    fclose(in);
    fclose(out);
    return 0;
}