洛谷刷题C语言:Olivander、取石子、Davor、标题统计、成绩

记录洛谷刷题QAQ


一、[COCI2017-2018#5] Olivander

题面翻译

题意简述

n n n 个棍子和 n n n 个盒子,要求每个盒子里放的棍子的总长度不能超过盒子的高度。求是否有方案使得各个棍子都能放到任意一个盒子里。是输出 DA,否则输出 NE。(一个盒子里只能放一根棍子)

输入

输入共三行。

第一行,一个整数 n n n

第二行, n n n 个整数 X 1 , X 2 , X 3 , … , X n X_1,X_2,X_3,\dots,X_n X1,X2,X3,,Xn。其中第 i i i个数 X i X_i Xi表示第 i i i根棍子的长度。

第三行, n n n个整数 Y 1 , Y 2 , Y 3 , … , Y n Y_1,Y_2,Y_3,\dots,Y_n Y1,Y2,Y3,,Yn。其中第 i i i 个数 Y i Y_i Yi 表示第 i i i 个盒子的高度。

输出

输出仅一行。即如果有能够将各个棍子都能放进任一盒子的方案输出 DA,否则输出 NE(输出不包括引号)。

样例解释

样例 1 1 1:哈利波特能够将所有棍子放进盒子里面。例如 X 1 ⇒ Y 3 , X 2 ⇒ Y 2 , X 3 ⇒ Y 1 X_1\Rightarrow Y_3,X_2\Rightarrow Y_2,X_3\Rightarrow Y_1 X1Y3,X2Y2,X3Y1

样例 2 2 2:哈利波特不能够将所有棍子放进盒子里。
因为 Y 2 = 2 Y_2=2 Y2=2,不能塞下任何一根棍子。

数据范围

对于 60 % 60\% 60% 的数据,保证 n ⩽ 9 n\leqslant9 n9

对于 100 % 100\% 100% 的数据,保证 n ⩽ 100 n\leqslant100 n100,并且 ∀ i \forall i i,都满足 X i , Y i ⩽ 1 0 9 X_i,Y_i\leqslant10^9 Xi,Yi109

题目描述

Harry Potter has damaged his magic wand in a fight with Lord Voldemort. He has decided to
get a new wand in Olivander’s wand shop. On the floor of the shop, he saw ​N wands and ​N
wand boxes. The lengths of the wands are, respectively, X 1 X_1 X1
, X 2 X_2 X2
…​ X n X_n Xn
, and the box sizes are
Y 1 Y_1 Y1
,​ Y 2 Y_2 Y2
Y n Y_n Yn
. A wand of length ​X can be placed in a box of size ​Y if ​X ≤ ​Y
. Harry wants to know
if he can place all the wands in boxes so that each box contains exactly one wand.
Help him solve this difficult problem.

输入格式

The first line of input contains the positive integer ​N
(1 ≤ ​N
≤ 100), the number from the task.
The second line contains ​N
positive integers ​ X i X_i Xi
(1 ≤ ​ X i X_i Xi
1 0 9 10^9 109​ ), the numbers from the task.
The third line contains ​N
positive integers ​ X i X_i Xi
(1 ≤ X i X_i Xi
1 0 9 10^9 109​​ ), the numbers from the task.

输出格式

If Harry can place all the wands in boxes, output “DA” (Croatian for yes), otherwise output
“NE” (Croatian for no).

样例 #1

样例输入 #1

3
7 9 5
6 13 10

样例输出 #1

DA

样例 #2

样例输入 #2

4
5 3 3 5
10 2 10 10

样例输出 #2

NE

样例 #3

样例输入 #3

4
5 2 3 2
3 8 3 3

样例输出 #3

DA

提示

In test cases worth 60% of total points, it will hold ​N
≤ 9.

Clarification of the first test case:

Harry can place the wands in boxes. For example, he can place the wand of length 5 in a box of size
6, wand of length 7 in a box of size 13, and wand of length 9 in a box of size 10.

Clarification of the second test case:

Harry can’t place the wands in boxes because the box of size 2 can’t fit any of the wands.

代码如下


#include
#include
#include
#include 

int main()

{
	int n;//盒子和棍子的总数
	scanf("%d",&n);
	
	int len[n];
	for(int i = 0;i < n;i++)
	{
		scanf("%d",&len[i]);
	}
	
	int high[n];
	for(int i = 0;i < n;i++)
	{
		scanf("%d",&high[i]);
	}
	
	for(int i = 0;i < n;i++)
	{
		for(int j =i;j < n;j++)
		{
			if(len[i] > len[j])
			{
				len[i] = len[i] + len[j];
				len[j] = len[i] - len[j];
				len[i]= len[i] - len[j];
			}
			
			if(high[i] >high[j])
			{
				high[i] = high[i] + high[j];
				high[j] = high[i] - high[j];
				high[i]= high[i] - high[j];
			}
		}
	}
	int num = 0;
	for(int i = 0 ;i < n;i++)
	{
		if(len[i] <= high[i])
		{
			num++;
		}
		else if(len[i] > high[i])
		{
			printf("NE\n");
			break;
		}
	}
	
	if(num == n)	printf("DA\n");
	return 0;
}

二、取石子

题目描述

Alice 和 Bob 在玩游戏。

他们有 n n n 堆石子,第 i i i 堆石子有 a i a_i ai 个,保证初始时 a i ≤ a i + 1 ( 1 ≤ i < n ) a_i \leq a_{i + 1}(1 \leq i < n) aiai+1(1i<n)。现在他们轮流对这些石子进行操作,每次操作人可以选择满足 a i > a i − 1 a_i > a_{i - 1} ai>ai1 a 0 a_0 a0 视为 0 0 0)的一堆石子,并从中取走一个。谁最后不能取了谁输。Alice 先手,他们都使用最优策略,请判断最后谁会取得胜利。

输入格式

第一行一个整数 n ( 1 ≤ n ≤ 100 ) n(1 \leq n \leq 100) n(1n100),表示石子堆数。

接下来一行 n n n 个数,第 i i i 个数为 a i ( 1 ≤ a i ≤ 1 0 9 ) a_i(1 \leq a_i \leq 10^9) ai(1ai109),意义如上所述。

输出格式

“Alice” 或 “Bob”,表示谁会赢。

样例 #1

样例输入 #1

1
1

样例输出 #1

Alice

样例 #2

样例输入 #2

1
2

样例输出 #2

Bob

代码如下

#include 
#include 
#define M  100


int main(int argc, char *argv[]) {
	int n;
	long long int NUM[M],sum = 0;
	int i;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%lld",&NUM[i]);
	} 
	for(i = 0;i < n;i++){
		sum = sum + NUM[i];
	}
	if(sum%2==0)
		printf("Bob");
	else 
		printf("Alice");
	return 0;
}

三、[COCI2017-2018#6] Davor

题面翻译

在征服南极之后,Davor 开始了一项新的挑战。下一步是在西伯利亚、格林兰、挪威的北极圈远征。他将在 2018 2018 2018 12 12 12 31 31 31 日开始出发,在这之前需要一共筹集 n n n 元钱。他打算在每个星期一筹集 x x x 元,星期二筹集 x + k x+k x+k 元,……,星期日筹集 x + 6 k x+6k x+6k 元,并连续筹集 52 52 52 个星期。其中 x , k x,k x,k 为正整数,并且满足 1 ≤ x ≤ 100 1 \le x \le 100 1x100

现在请你帮忙计算 x , k x,k x,k 为多少时,能刚好筹集 n n n 元。

如果有多个答案,输出 x x x 尽可能大, k k k 尽可能小的。注意 k k k 必须大于 0 0 0

题目描述

After successfully conquering the South Pole, Davor is preparing for new challenges. Next up is the Arctic expedition to Siberia, Greenland and Norway. He begins his travels on 31 December 2018, and needs to collect ​N kunas (Croatian currency) by then. In order to do this, he has decided to put away ​X (​X ≤ 100) kunas every Monday to his travel fund, ​X + K kunas every Tuesday, ​X + 2* ​K every Wednesday, and so on until Sunday, when he will put away ​X + 6* ​K kunas. This way, he will collect money for 52 weeks, starting with 1 January 2018 (Monday) until 30 December 2018 (Sunday).

If we know the amount of money ​N​, output the values ​X and ​K so that it is possible to collect the ​exact money amount in the given timespan. The solution will always exist, and if there are multiple, output the one with the greatest ​X ​ and smallest ​K ​.

输入格式

The first line of input contains the integer ​N​ (1456 ≤ ​N​ ≤ 145600), the number from the task.

输出格式

The first line of output must contain the value of ​X (​0 < ​X ​≤ 100 ​)​, and the second the value of
K (K ​> 0 ​)​.

样例 #1

样例输入 #1

1456

样例输出 #1

1
1

样例 #2

样例输入 #2

6188

样例输出 #2

14
1

样例 #3

样例输入 #3

40404

样例输出 #3

99
4

代码如下

#include
#include
#include
#include 

int main()

{
	int n, k = 1;
	long long num;
	scanf("%lld",&num);
	
	int price = num / 364;
	do
	{
		n = price - 3*k;
		k++;
	}
	while(n > 100);
	
	printf("%d\n",n);
	printf("%d\n",k - 1);
	return 0;
}

四、[NOIP2018 普及组] 标题统计

题目描述

凯凯刚写了一篇美妙的作文,请问这篇作文的标题中有多少个字符? 注意:标题中可能包含大、小写英文字母、数字字符、空格和换行符。统计标题字 符数时,空格和换行符不计算在内。

输入格式

输入文件只有一行,一个字符串 s s s

输出格式

输出文件只有一行,包含一个整数,即作文标题的字符数(不含空格和换行符)。

样例 #1

样例输入 #1

234

样例输出 #1

3

样例 #2

样例输入 #2

Ca 45

样例输出 #2

4

提示

【输入输出样例 1 说明】
标题中共有 3 个字符,这 3 个字符都是数字字符。

【输入输出样例 2 说明】 标题中共有$ 5$ 个字符,包括 1 1 1 个大写英文字母, 1 1 1 个小写英文字母和 2 2 2 个数字字符, 还有 1 1 1 个空格。由于空格不计入结果中,故标题的有效字符数为 4 4 4 个。

【数据规模与约定】
规定 ∣ s ∣ |s| s 表示字符串 s s s 的长度(即字符串中的字符和空格数)。
对于 40 % 40\% 40% 的数据, 1 ≤ ∣ s ∣ ≤ 5 1 ≤ |s| ≤ 5 1s5,保证输入为数字字符及行末换行符。
对于 80 % 80\% 80% 的数据, 1 ≤ ∣ s ∣ ≤ 5 1 ≤ |s| ≤ 5 1s5,输入只可能包含大、小写英文字母、数字字符及行末换行符。
对于 100 % 100\% 100% 的数据, 1 ≤ ∣ s ∣ ≤ 5 1 ≤ |s| ≤ 5 1s5,输入可能包含大、小写英文字母、数字字符、空格和行末换行符。

代码如下

#include
#include
#include
#include 

int main()

{
	char num[6];
	gets(num);//读入一行 
	
	int len = strlen(num);

	
	int sum = 0;
	for(int i = 0;i < len;i++)
	{
		if(num[i] >= 'A'&&num[i] <='Z')
		{
			sum++;
		}
		if(num[i] >= '0'&&num[i] <='9')
		{
			sum++;
		}
		if(num[i] >= 'a'&&num[i] <='z')
		{
			sum++;
		}
	}
	
	printf("%d\n",sum);
	return 0;
}

五、成绩

题目背景

小奔的score

题解:https://blog.csdn.net/kkkksc03/article/details/84928268

说一句:本题已放开空间范围(不过真的貌似不用开数组就可以A呀

题目描述

小奔的期末考试结束了。

他的成绩不久之后就会发下来。

给出一个考试成绩表格,例如:

科目/分值种类 语文 数学 英语
满分 100 100 100 120 120 120 150 150 150
实际得分 99 99 99 73 73 73 100 100 100

当然。学校的老师认为如果录入如此多的成绩不好算分,于是他想要你的综合成绩评定

综合成绩评定指:(每一科的满分之和*3-每一科的实际得分之和*2)÷每科所扣除分数的和。

小奔想请你给出他的综合成绩,你能做到吗?

输入格式

第一行给出一个整数 n n n,表示科目的总数。
第二行 n n n个整数 a i a_i ai,表示第 i i i门课程的满分。
第三行 n n n个整数 b i b_i bi,表示第 i i i门课程小奔的实际得分。

输出格式

一行一个数,表示他的综合成绩。结果保留 6 6 6位小数

样例 #1

样例输入 #1

3
10 10 10
5 5 5

样例输出 #1

4.000000

提示

对于 20 20 20%的数据,数据为样例

对于 100 100 100%的数据, n < = 1 e 7 n<=1e7 n<=1e7

代码如下

#include
int main()
{
	double n, sum1 = 0, sum2 = 0, score;
	scanf("%lf", &n);
	for(int i = 0; i < n; i++)
	{
		scanf("%lf", &score);
		sum1 += score;
	}
	for(int i = 0; i < n; i++)
	{
		scanf("%lf", &score);
		sum2 += score;
	}
	printf("%.6lf", (sum1 * 3 - sum2 * 2) / (sum1 - sum2));
	return 0;
}

你可能感兴趣的:(C语言学习,洛谷,c语言)