Cod sursa(job #546078)

Utilizator udrescu_cristiUdrescu Cristian udrescu_cristi Data 4 martie 2011 12:53:37
Problema Walls Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include<stdio.h>
#include<algorithm>

#define nmax 100001

 int c1[nmax],c2[nmax],h[nmax],hx[nmax],hy[nmax];
 int n,m,i,j,x,y,q,t,t1,k,nr,t2;
 
  int main()
{
	freopen("walls.in","r",stdin);
	freopen("walls.out","w",stdout);
	
	
	c2[0]=-1;
	scanf("%d\n",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d\n",&x,&y);
		c1[i]=c2[i-1]+2;
		c2[i]=c1[i]+x-1;
		h[i]=y;
	}
	scanf("%d\n",&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d\n",&x,&y);
		t2=1;
 for(j=n;j>=1&&t2;j--)
 {
	if(x>c2[j])
	{
    	if(y<=h[j])
		{
			t1=1;
			t2=0;
		for(q=c2[j];q>=c1[j]&&t1;q--)
		{
			t=1;
		for(k=1;k<=nr;k++)
		 if(hx[k]==q&&hy[k]==y)
			 t=0;
		if(t)
		{
			t1=0;
			nr++;
			hx[nr]=q;
			hy[nr]=y;
		if(q!=c1[j]) printf("HIT %d %d NO\n",q,j);
		else
		{ 
			printf("HIT %d %d YES\n",q,j);
			h[j]=y-1;
		}
		}
		}
		}
	}
 }
 if(t2) printf("MISS\n");
	}
 return 0;
  }