LightOJ-1425 the Monkey and the oiled Bamboo (water)

Source: Internet
Author: User
LightOJ-1425 the Monkey and the oiled Bamboo
Time Limit: 3000MS Memory Limit: 32768KB 64bit IO Format: %lld &%llu

Submit Status

Description

It's time to remember the disastrous moment of the old school math. Yes, the little math problem with the monkey climbing in an oiled bamboo. It goes like:

"A Monkey is trying to reach the top of an oiled bamboo. When he climbs up 3 feet, he slips down 2 feet. Climbing up 3 feet takes 3 seconds. Slipping down 2 feet takes 1 second. If The pole is a feet tall, how much time does the monkey need to reach the top? "

When I was given the problem, I took it seriously. But after a while I was thinking of killing the monkey instead of doing the horrible math! I had rather different plans (!) for the mans who oiled the bamboo.

Now we, the problem-setters, got a similar oiled bamboo. So, we thought we could do better than the traditional monkey. So, I tried first. I jumped and climbed up 3.5 feet (better than the monkey! huh!) The very next second I just slipped and fell off to the ground. I couldn ' t remember anything after then, when I woke up, I found myself in a bed and the anxious faces of the problem sett ERs around me. So, as the old school times, the monkey won with the oiled bamboo.

So, I made another plan (somehow I want to beat the monkey), I took a ladder instead of the bamboo. Initially I am on the ground. In each jump I can jump from the current rung (or the ground) to the next rung only (can ' t skip rungs). Initially I set my strength factor K. The meaning of K are, in any jump I can ' t jump to more thanK feet. And if I jump exactly k feet in a jump, K is decremented by 1. But if I jump less than k feet, k remains same.

For example, let the height of the rungs from the ground is 1, 6, 7, one, respectively and K be 5. Now the steps is:

1. Jumped 1 foot from the ground to the 1st rung (ground to 1). Since I jumped less than k feet, k remains 5.

2. Jumped 5 feet for the next rung (1 to 6). So, K becomes 4.

3. Jumped 1 foot for the 3rd rung (6 to 7). So, K remains 4.

4. Jumped 4 feet for the 4th rung (7 to 11). Thus k becomes 3.

5. Jumped 2 feet for the 5th rung (one to 13). And so, K remains 3.

Now is given the heights of the rungs of the ladder from the ground and you have to find the minimum strength factor k, such that I can reach the top rung.

Input

Input starts with an integer T (≤12), denoting the number of test cases.

Each case is starts with a line containing an integer n (1≤n≤105) denoting the number of rungs in the ladder. The next line contains n space separated integers, r1, R2 ..., RN (1≤R1 < R2 < ... < rn≤109) denoting The heights of the rungs from the ground.

Output

For each case, print the case number and the minimum possible value of K as described above.

Sample Input

2

5

1 6 7) 11 13

4

3 9 10 14

Sample Output

Case 1:5

Case 2:6

Source problem Setter:jane Alam Jan Special Thanks:sohel Hafiz//test instructions: Enter a number n, followed by a line of n number to indicate the height of your step I, ask the minimum climb distance k is how much to get you to climb to the pole Top. Of course, climbing is a rule, if you climb a certain step distance is equal to K, the value of K will be reduced by 1, otherwise it has been K (the climb distance of a step can not exceed K). Idea: According to test instructions regulations, first find the height difference between two adjacent heights mm, and then use this maximum mm traverse this n height difference, see if meet test instructions, if not meet, then k==mm+1, otherwise k==mm; Hait: You started at 0 height (once in this WA).

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream >
#define N 100010
using namespace std;
int a[n],b[n];
int main ()
{
	int t,t=1,n,i,j,k;
	scanf ("%d", &t);
	while (t--)
	{
		scanf ("%d", &n);
		scanf ("%d", &a[0]);
		B[0]=A[0];
		int mm=b[0];
		for (i=1;i<n;i++)
		{
			scanf ("%d", &a[i]);
			B[I]=A[I]-A[I-1];
			Mm=max (Mm,b[i]);
		}
		int m=mm;
		int flag=0;
		for (i=1;i<n;i++)
		{
			if (Mm==b[i])
				mm--;
			else if (Mm<b[i])
			{
				flag=1;
				break;
			}
		}
		printf ("Case%d:", t++);
		if (flag)
			printf ("%d\n", m+1);
		else
			printf ("%d\n", m);
	}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.