View Code of Problem 6

#include  <stdio.h>
#include  <stdlib.h>
#include  <math.h>
#include  <string.h>

#define LEN 100

int jump(int step,int l[],int num,int r[])
{
	int len,i;
	len=step;
	for(i=1;i<num-1;i++)
	{
		len+=step;
		if(len<r[i]||len>l[i+1])
			return 0;
	}
	len+=step;
	if(len<r[i])	return 0;

	return 1;	
}

int main()
{
    int t, n;
    int a[LEN], b[LEN];
    int i, j, kj, kab;
    int step_s = 1, step_e = 10000;/*
	if(freopen("c:\\input.txt", "rt", stdin)==0)
	{
	}*/

    scanf ("%d",&t);
    for (i=0; i<t; i++)
    {
        scanf("%d", &n);
        for (j=0; j<n; j++)
        {
            scanf("%d%d", &a[j], &b[j]);            
        }
        step_s = b[0];// first step is b[0] ,a[0] must be 0.
        step_e = a[1];// last step is a[1], per one trap
        
		while(step_s<=step_e)
		{
			
			if(jump(step_s,a,n,b)==1)
			{
				printf("YES\n");
				break;
			}
			step_s++;
		}
		if(step_s>a[1])
			printf("NO\n");		
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 6