Pagini recente » Cod sursa (job #2981750) | Cod sursa (job #2095366) | Cod sursa (job #2788056) | Cod sursa (job #464579) | Cod sursa (job #541731)
Cod sursa(job #541731)
#include <cstdio>
//consts
const int NMAX=8393;
//structs
struct Lovitura {int etaj, n;};
struct Zid{int x,h,w,nlov; Lovitura lovituri[29];};
//global
int main(){
freopen("walls.in","r",stdin);
freopen("walls.out","w",stdout);
//vars
int n;
int np;//no bullets
Zid v[NMAX];
int x,y;
int i,j,k;//cycle
//read A
scanf("%d",&n);
scanf("%d%d",&v[0].w,&v[0].h); v[0].x=v[0].w;
for(i=1;i<n;++i){
scanf("%d%d",&v[i].w,&v[i].h);
v[i].x=v[i].w+v[i-1].x+1;
}
//read B
bool ok;
bool fost_lovit;
scanf("%d",&np);
for(i=0;i<np;++i){
scanf("%d%d",&x,&y);
ok=false;
for(j=n-1;j>=0;--j){
if(v[j].h>=y && v[j].x<x){
ok=true;
fost_lovit=false;
for(k=0;k<v[j].nlov;++k)
if(v[j].lovituri[k].etaj==y){//a mai fost lovit in acel etaj
fost_lovit=true;
printf("HIT %d %d ",v[j].x-v[j].lovituri[k].n,j+1);
++v[j].lovituri[k].n;
if (v[j].lovituri[k].n==v[j].w){//if the entire row is destroyed
printf("YES\n");
v[j].h=v[j].lovituri[k].etaj-1;
}
else{
printf("NO\n");
}
}
if(!fost_lovit){//nu a mai fost lovit in acel etaj
printf("HIT %d %d ",v[j].x,j+1);
v[j].lovituri[v[j].nlov].n=1;
v[j].lovituri[v[j].nlov].etaj=y;
if(v[j].w==1){//daca nu e format decat dintr-o bucata, am distrus etajul
printf("YES\n");
v[j].h=v[j].lovituri[v[j].nlov].etaj-1;
}
else printf("NO\n");
++v[j].nlov;
}
break;
}
}
if(!ok) printf("MISS\n");
}
return 0;
}