ccpc训练营练习题(1)

FOJ有奖月赛-2014年11月

文章目录

  • C - ytaaa
    • Input
    • Output
    • Sample Input
    • Sample Output
  • G - 快来买肉松饼
    • Input
    • Output
    • Sample Input
    • Sample Output
  • H - 水题
    • Input
    • Output
    • Sample Input
    • Sample Output

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
#include
#include
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
#include

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;
} 

你可能感兴趣的:(#,区域赛题目)