Pagini recente » Cod sursa (job #569884) | Istoria paginii utilizator/dorin.rotarescu | Profil exquisite | Istoria paginii utilizator/ubb_lili | Cod sursa (job #541749)
Cod sursa(job #541749)
#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,Gy);
if(!okcazut)
fprintf(out,"NO\n");
else
fprintf(out,"YES\n");
break;
}
}
}
if(!ok)
fprintf(out,"MISS\n");
}
return 0;
}