Pagini recente » Cod sursa (job #1198519) | Cod sursa (job #1279263) | Cod sursa (job #482574) | Cod sursa (job #673006) | Cod sursa (job #541874)
Cod sursa(job #541874)
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef struct zid
{
int lat;
int h;
int x;
vector<int> lovit;
};
vector<zid> v(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[0].lat,&v[0].h);
v[0].x=1;
for(i=1;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;
}
fscanf(in,"%d",&m);
for(i=1;i<=m;i++)
{
fscanf(in,"%d %d",&Gx,&Gy);
bool ok=false;
bool okcazut=false;
for(j=n-1;j>=0;j--)
{
if(v[j].h>=Gy && v[j].x<Gx)
{
int cnt;
ok=true;
fprintf(out,"HIT");
cnt=count(v[j].lovit.begin(),v[j].lovit.end(),Gy);
if(cnt+1==v[j].lat)
{
okcazut=true;
v[j].h=Gy-1;
}
if(!v[j].h)
{
v.erase(v.begin()+j);
n--;
}
v[j].lovit.push_back(Gy);
fprintf(out," %d %d ",v[j].x+v[j].lat-cnt-1,j+1);
if(!okcazut)
fprintf(out,"NO\n");
else
fprintf(out,"YES\n");
break;
}
}
if(!ok)
fprintf(out,"MISS\n");
}
fclose(in);
fclose(out);
return 0;
}