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<stdio.h>
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 <total;i++)
	{
		if (a[i] <= low)
		{
			low = a[i];
			l_place = i;
		}
	}

	while(l_place != total-1)
	{
		temp = a[l_place];
		a[l_place] = a[l_place + 1];
		a[l_place + 1] = temp;
		l_place++;
		count ++;
	}
	printf("%d\n", count);
	return 0;
}

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<stdio.h>
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 <total;i++)
	{
		if (a[i] <= low)
		{
			low = a[i];
			l_place = i;
		}
	}

	while(l_place != total-1)
	{
		temp = a[l_place];
		a[l_place] = a[l_place + 1];
		a[l_place + 1] = temp;
		l_place++;
		count ++;
	}
	printf("%d\n", count);
	return 0;
}

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<stdio.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<math.h>
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<len;i++)
		{
			if(s[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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
城市应急指挥系统是智慧城市建设的重要组成部分,旨在提高城市对突发事件的预防和处置能力。系统背景源于自然灾害和事故灾难频发,如汶川地震和日本大地震等,这些事件造成了巨大的人员伤亡和财产损失。随着城市化进程的加快,应急信息化建设面临信息资源分散、管理标准不统一等问题,需要通过统筹管理和技术创新来解决。 系统的设计思路是通过先进的技术手段,如物联网、射频识别、卫星定位等,构建一个具有强大信息感知和通信能力的网络和平台。这将促进不同部门和层次之间的信息共享、交流和整合,提高城市资源的利用效率,满足城市对各种信息的获取和使用需求。在“十二五”期间,应急信息化工作将依托这些技术,实现动态监控、风险管理、预警以及统一指挥调度。 应急指挥系统的建设目标是实现快速有效的应对各种突发事件,保障人民生命财产安全,减少社会危害和经济损失。系统将包括预测预警、模拟演练、辅助决策、态势分析等功能,以及应急值守、预案管理、GIS应用等基本应用。此外,还包括支撑平台的建设,如接警中心、视频会议、统一通信等基础设施。 系统的实施将涉及到应急网络建设、应急指挥、视频监控、卫星通信等多个方面。通过高度集成的系统,建立统一的信息接收和处理平台,实现多渠道接入和融合指挥调度。此外,还包括应急指挥中心基础平台建设、固定和移动应急指挥通信系统建设,以及应急队伍建设,确保能够迅速响应并有效处置各类突发事件。 项目的意义在于,它不仅是提升灾害监测预报水平和预警能力的重要科技支撑,也是实现预防和减轻重大灾害和事故损失的关键。通过实施城市应急指挥系统,可以加强社会管理和公共服务,构建和谐社会,为打造平安城市提供坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值