ACM:Cancer's Trial(1)

A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.

By the military charter the soldiers should stand in the order of non-increasing of their height. But as there’s virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.

For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.

Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.

Input
The first input line contains the only integer n (2 ≤ n ≤ 100) which represents the number of soldiers in the line. The second line contains integers a1, a2, …, an (1 ≤ ai ≤ 100) the values of the soldiers’ heights in the order of soldiers’ heights’ increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers a1, a2, …, an are not necessarily different.
Output
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
Examples
Input
4
33 44 11 22
Output
2
Input
7
10 10 58 31 63 40 76
Output
10
Note
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
(10, 10, 58, 31, 63, 40, 76)
(10, 58, 10, 31, 63, 40, 76)
(10, 58, 10, 31, 63, 76, 40)
(10, 58, 10, 31, 76, 63, 40)
(10, 58, 31, 10, 76, 63, 40)
(10, 58, 31, 76, 10, 63, 40)
(10, 58, 31, 76, 63, 10, 40)
(10, 58, 76, 31, 63, 10, 40)
(10, 76, 58, 31, 63, 10, 40)
(76, 10, 58, 31, 63, 10, 40)
(76, 10, 58, 31, 63, 40, 10)

AC:

#include
int a[1000] = {0};
int main()
{
	int total = 0, count = 0,high = 0,h_place = 0,low = 0,l_place = 0;
	scanf("%d", &total);
	int i = 0,temp = 0;
	
	for (i = 0; i < total; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] > high)
		{
			high = a[i];
			h_place = i;
		}
	}
	
	while(h_place)
	{
		temp = a[h_place];
		a[h_place] = a[h_place - 1];
		a[h_place - 1] = temp;
		h_place --;
		count ++;
	}

	low = a[0];
	for (i = 0; i 

There is a game called “I Wanna Be the Guy”, consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.

Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input

The first line contains a single integer n (1 ≤  n ≤ 100).

The next line contains an integer p (0 ≤ p ≤ n) at first, then follows p distinct integers a1, a2, ..., ap (1 ≤ ai ≤ n). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to n.

Output

If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).

Examples
Input
4
3 1 2 3
2 2 4
Output
I become the guy.
Input
4
3 1 2 3
2 2 3
Output
Oh, my keyboard!
Note
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4.

AC:

#include
int a[1000] = {0};
int main()
{
	int total = 0, count = 0,high = 0,h_place = 0,low = 0,l_place = 0;
	scanf("%d", &total);
	int i = 0,temp = 0;
	
	for (i = 0; i < total; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] > high)
		{
			high = a[i];
			h_place = i;
		}
	}
	
	while(h_place)
	{
		temp = a[h_place];
		a[h_place] = a[h_place - 1];
		a[h_place - 1] = temp;
		h_place --;
		count ++;
	}

	low = a[0];
	for (i = 0; i 

Pirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some ways, she will type the key at least. But she has a bad habit that if the caps lock is on, she must turn off it, after she finishes typing. Now she wants to know the smallest times of typing the key to finish typing a string.
Input
The first line is an integer t (t<=100), which is the number of test case in the input file. For each test case, there is only one string which consists of lowercase letter and upper case letter. The length of the string is at most 100.
Output
For each test case, you must output the smallest times of typing the key to finish typing this string.
Sample Input
3
Pirates
HDUacm
HDUACM
Sample Output
8
8
8

Hint
The string “Pirates”, can type this way, Shift, p, i, r, a, t, e, s, the answer is 8.
The string “HDUacm”, can type this way, Caps lock, h, d, u, Caps lock, a, c, m, the answer is 8
The string “HDUACM”, can type this way Caps lock h, d, u, a, c, m, Caps lock, the answer is 8

AC:

#include
#include
#include
#include
#include
#include
char s[1000];
int capon[500] = {0};
int capoff[500] = {0};
using namespace std;
int main()
{
	int total = 0,len = 0;
	int i = 0;
	scanf("%d",&total);
	while(total--)
	{
		scanf("%s",s);
		len=strlen(s);
		memset(capon,0,sizeof(capon));
		memset(capoff,0,sizeof(capoff));
		
		capon[0]=1;
		capoff[0]=0;
		for(i=0;i='a'&&s[i]<='z')
			{
				capon[i+1]=min(capon[i]+2,capoff[i]+2);
				capoff[i+1]=min(capon[i]+2,capoff[i]+1);
			}
			else
			{
				capon[i+1]=min(capon[i]+1,capoff[i]+2);
				capoff[i+1]=min(capon[i]+2,capoff[i]+2);
			}

		}
	
		printf("%d\n",min(capon[len]+1,capoff[len]));
	}
	return 0;
}

你可能感兴趣的:(ACM:Cancer's Trial(1))