ccpc訓練營練習題(1)

FOJ有獎月賽-2014年11月

C - ytaaa

Ytaaa作爲一名特工執行了無數困難的任務,這一次ytaaa收到命令,需要炸燬敵人的一個工廠,爲此ytaaa需要製造一批炸彈以供使用。 Ytaaa使用的這種新型炸彈由若干個炸藥組成,每個炸藥都有它的威力值,而炸彈的威力值爲組成這個炸彈的所有炸藥的最大威力差的平方,即(max-min)^2,假設一個炸彈有5個炸藥組成,威力分別爲5 9 8 2 1,那麼它的威力爲(9-1)^2=64。現在在炸彈的製造流水線上已經有一行n個炸藥,由於時間緊迫,ytaaa並沒有時間改變它們的順序,只能確定他們的分組。作爲ytaaa的首席顧問,請你幫助ytaaa確定炸藥的分組,使製造出的炸彈擁有最大的威力和。

Input

輸入由多組數據組成。第一行爲一個正整數n(n<=1000),第二行爲n個數,第i個數a[i]爲第i個炸藥的威力值(0<=a[i]<=1000)。

Output

對於給定的輸入,輸出一行一個數,爲所有炸彈的最大威力和。

Sample Input

6
5 9 8 2 1 6

Sample Output

77

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=1e3+5;

int arr[N],dp[N];

int main(void)
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;i++)
			scanf("%d",&arr[i]);
		memset(dp,0,sizeof dp);
		int ma,mi; 
		for(int i=1;i<=n;i++)
		{
			ma=mi=arr[i];
			for(int j=i;j>=1;j--)
			{
				ma=max(ma,arr[j]);
				mi=min(mi,arr[j]);
				dp[i]=max(dp[i],dp[j-1]+(ma-mi)*(ma-mi));
			}
		}
		printf("%d\n",dp[n]);
	}
	return 0;
}

G - 快來買肉鬆餅

轉眼又到了一年一度的聖戰(光棍)節了,單身狗大表哥決定和一羣一樣孤獨的盆友一起出來過節,一起玩遊戲,輸的人給贏的人買肉鬆餅,這樣大家都不會感到孤單。

爲了防止平局出現,大表哥給大家準備了一個奇數(大於一的奇數)個人可以圍成一圈一起玩的遊戲(每個人必須與兩個人相鄰)。大表哥希望大家都能參加到遊戲裏去,但無奈有些盆友之間有誤會,有誤會的盆友不能坐在相鄰的位置一起愉快的玩耍。每個人可以同時參與多個遊戲,但當所有能參與遊戲的人數小於K時,大表哥將取消這次聚會。

Input

輸入第一行一個整數T(T ≤ 100)表示共T組數據。

每組數據第一行三個數N,M,K表示大表哥共有N個盆友,M表示有M對誤會關係,當所有參與人數大於等於K時大表哥舉辦聚會。(1 ≤ N≤ 1000 , 1 ≤ M ≤ 1000000,3 ≤ K)

接下來M行每行兩個數a,b分別代表編號a和編號b的盆友間存在誤會。(編號從1到n,誤會關係可能重複)

Output

若大表哥可以舉行聚會輸出“Let’s Fire!”,否則輸出“What a Pity.”。

Sample Input

1
5 5 3
1 4
1 5
2 5
3 4
3 5

Sample Output

Let’s Fire!

題解鏈接:https://blog.csdn.net/m0_37846371/article/details/77951373

H - 水題

胖哥自從當上公務員,贏取白富美,走向人生巔峯後,已經懶散到不想出題了,不僅如此,他連題目都懶得看了,現在他只會根據題目第一個單詞的長度判定這個題目的難度

如果題目的第一個單詞太長(長度大於3),他會說這題太難,不可能想的出來; 如果題目的第一個單詞太短(長度不大於3),他會說這題太簡單,懶得去想

現在給定一個題目,L想知道胖哥對於這道題會作出什麼反應

Input

首先是一個正整數cas,表示有cas組輸入,cas<=100

對於每組輸入,會給出一行,每行表示一個題目,每個題目只會由大寫字母,小寫字母或者空格構成,每行的第一個字符一定不會是空格,多個空格可能連續出現,每行最多200個字符

Output

對於每個題目,如果胖哥覺得這題太難,輸出"Too hard!",否則輸出"Too easy!"

Sample Input

12
If    the   day    is    done
If birds sing no more
If the wind has fiagged tired
Then draw the veil of darkness thick upon me
Even as thou hast wrapt the earth with The coverlet of sleep and tenderly closed
The petals of the drooping lotus at dusk
From the travere
Whose sack of provisions is empty before the voyage is ended
Whose garment is torn and dustladen
Whose strength is exhausted remove shame and poverty
And renew his life like a flower  under
The cover of thy kindly night

Sample Output

Too easy!
Too easy!
Too easy!
Too hard!
Too hard!
Too easy!
Too hard!
Too hard!
Too hard!
Too hard!
Too easy!
Too easy!

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

char str[205];

int main(void)
{
	int t,len,num;
	scanf("%d",&t);
	getchar();
	while(t--)
	{
		num=0;
		gets(str);
		len=strlen(str);
		for(int i=0;i<len;i++)
		{
			if(str[i]!=' '&&str[i])
				num++;
			else
				break;
		}
		if(num>3)
			printf("Too hard!\n");
		else
			printf("Too easy!\n");
	}
	return 0;
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章