CodeForces刷题C语言:Army、Blinds、Cubical Planet、Find Color、Translation

63 篇文章 7 订阅
7 篇文章 0 订阅

记录洛谷刷题C语言


一、Army

题面翻译

题目描述

在北爱尔兰军队的行政系统中有 n n n 个军衔,其中 1 1 1 最低, n n n 最高。

你需要 d i d_i di 年来从 i i i 级升到 i + 1 i+1 i+1 级。在你升到 i i i 级时必须已经到达前面所有等级。

Vasya 刚刚达到 a a a 级,但他想达到 b b b 级。请问他至少还要再参军多少年。

输入格式

第一行: n n n 2 ≤ n ≤ 100 2 \leq n \leq 100 2n100);

第二行: d 1 d_1 d1 d 2 d_2 d2 d 3 … … d n − 1 d_3……d_{n-1} d3……dn1 1 ≤ d i ≤ 100 1 \leq d_i \leq 100 1di100);

第三行: a , b a,b a,b 1 1 1 ≤ \leq a a a < < < b b b ≤ \leq n n n)。

输出格式

仅一行:从 a a a 级升到 b b b 级所需的年数。

题目描述

The Berland Armed Forces System consists of $ n $ ranks that are numbered using natural numbers from $ 1 $ to $ n $ , where $ 1 $ is the lowest rank and $ n $ is the highest rank.

One needs exactly $ d_{i} $ years to rise from rank $ i $ to rank $ i+1 $ . Reaching a certain rank $ i $ having not reached all the previous $ i-1 $ ranks is impossible.

Vasya has just reached a new rank of $ a $ , but he dreams of holding the rank of $ b $ . Find for how many more years Vasya should serve in the army until he can finally realize his dream.

输入格式

The first input line contains an integer $ n $ ( $ 2<=n<=100 $ ). The second line contains $ n-1 $ integers $ d_{i} $ ( $ 1<=d_{i}<=100 $ ). The third input line contains two integers $ a $ and $ b $ ( $ 1<=a<b<=n $ ). The numbers on the lines are space-separated.

输出格式

Print the single number which is the number of years that Vasya needs to rise from rank $ a $ to rank $ b $ .

样例 #1

样例输入 #1

3
5 6
1 2

样例输出 #1

5

样例 #2

样例输入 #2

3
5 6
1 3

样例输出 #2

11

代码如下

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

int main()
{
	int n;
	scanf("%d",&n);
	
	int num[n];
	for(int i = 1;i < n;i++)
	{
		scanf("%d",&num[i]);
	}
	
	int a, b;
	scanf("%d%d",&a,&b);
	int sum = 0;
	for(int i = a;i < b;i++)
	{
		sum = sum + num[i];
	}
	printf("%d\n",sum);
	return 0;
}

二、Blinds

题面翻译

n n n 条长度为 a i a_i ai 宽度为 1 1 1 的横条,用这 n n n 个横条做一个百叶窗,百叶窗每行的横条长度均要相同且不小于 l l l ,横条可以切断但不能拼接,且百叶窗每行的横条长度为正整数,输出百叶窗的最大面积。

题目描述

The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are $ n $ blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they may not have the same length (it is even possible for them to have different lengths)

Every stripe can be cut into two or more parts. The cuttings are made perpendicularly to the side along which the length is measured. Thus the cuttings do not change the width of a stripe but each of the resulting pieces has a lesser length (the sum of which is equal to the length of the initial stripe)

After all the cuttings the blinds are constructed through consecutive joining of several parts, similar in length, along sides, along which length is measured. Also, apart from the resulting pieces an initial stripe can be used as a blind if it hasn’t been cut. It is forbidden to construct blinds in any other way.

Thus, if the blinds consist of $ k $ pieces each $ d $ in length, then they are of form of a rectangle of $ k×d $ bourlemeters.

Your task is to find for what window possessing the largest possible area the blinds can be made from the given stripes if on technical grounds it is forbidden to use pieces shorter than $ l $ bourlemeter. The window is of form of a rectangle with side lengths as positive integers.

输入格式

The first output line contains two space-separated integers $ n $ and $ l $ ( $ 1<=n,l<=100 $ ). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated $ n $ integers $ a_{i} $ . They are the lengths of initial stripes in bourlemeters ( $ 1<=a_{i}<=100 $ ).

输出格式

Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number $ 0 $ .

样例 #1

样例输入 #1

4 2
1 2 3 4

样例输出 #1

8

样例 #2

样例输入 #2

5 3
5 5 7 3 1

样例输出 #2

15

样例 #3

样例输入 #3

2 3
1 2

样例输出 #3

0

提示

In the first sample test the required window is $ 2×4 $ in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length of 4 cut in halves.

代码如下

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


int n,l,ans=0,mx=-1,a[10005];//ans是当前长度能得到的叶片数量,mx是当前最大的百叶窗面积。
int main()
{
    scanf("%d%d",&n,&l);
    for(int i=1;i<=n;i++)
    	scanf("%d",&a[i]);//输入每个叶片的长度
    for(int i=l;i<=100;i++)//从l到100(因为a[i]最大值为100)都枚举一遍
    {
    	ans=0;
    	for(int j=1;j<=n;j++)
    		ans=ans+a[j]/i;//a[j]/i表示第j个叶片能割多少个长度为i的叶片
    	if(ans*i >= mx)
			mx = ans*i;//比较取最大值
    }
    printf("%d\n",mx);//输出最大的面积
    return 0;//233啦
}

三、Cubical Planet

题面翻译

题面描述

银河系中没有你找不到的东西!有一颗形状为立方体的的行星正在绕着一颗形状为二十面体的恒星运转。现在我们让这颗行星的两个在同一条体对角线上的顶点置于 ( 0 , 0 , 0 ) (0,0,0) (0,0,0) ( 1 , 1 , 1 ) (1,1,1) (1,1,1) 上。有两只苍蝇住在行星上。这俩家伙分别坐在这颗行星的两个不同的顶点上。
问题是:你需要确定,这俩可怜虫会不会见面。前提是:如果他俩所在的顶点位于这颗行星的同一个面上(六个面),他们就算见到彼此了。

输入格式

第一行包括三个用空格分开的整数,表示第一只苍蝇的坐标。
第二行也包括三个用空格分开的整数,表示第二只苍蝇所在的坐标。

输出格式

如果这两只可怜虫能见到彼此,则输出:YES。否则,输出NO

题目描述

You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points $ (0,0,0) $ and $ (1,1,1) $ . Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube.

输入格式

The first line contains three space-separated integers ( $ 0 $ or $ 1 $ ) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly.

输出格式

Output “YES” (without quotes) if the flies see each other. Otherwise, output “NO”.

样例 #1

样例输入 #1

0 0 0
0 1 0

样例输出 #1

YES

样例 #2

样例输入 #2

1 1 0
0 1 0

样例输出 #2

YES

样例 #3

样例输入 #3

0 0 0
1 1 1

样例输出 #3

NO

代码如下

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

int main(){
    int a[4],b[4],i;  
    for ( i = 1 ; i <= 3 ; i++ )
        scanf("%d",&a[i]);
    for ( i = 1 ; i <= 3 ; i++ )
        scanf("%d",&b[i]);
    
    for ( i = 1 ; i <= 3 ; i++ )  
    {
        if ( a[i] == b[i] )  
        {
            printf("YES\n");
            return 0;
        
        }
    }
    printf("NO\n"); 
    return 0;
}

四、Find Color

题面翻译

题面描述

不久前,由于战争,Berland 的主要标志魔力钟损坏了。大炮在钟面上炸出了几个洞。这就是为什么居民要修复这个钟的原因。这个钟可以看做一个无限的 Cartesian 平面。钟被涂上了两种颜色,如图所示:

这张图只显示了魔力钟的中心部位,颜色一直按照此规律延伸到无穷远处。

炮弹可以看做平面上的点。你的任务就是找到被炮弹损坏区域的颜色。

位于边界上的点必须被认为黑色。

输入格式

输入仅一行,包含了两个整数 x x x y y y——炮弹在钟面上的坐标。每个数字 x x x y y y 的绝对值不超过 1000 1000 1000

输出格式

找到的颜色。位于边界上的点必须被认为黑色。

题目描述

Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon’s balls made several holes in the clock, that’s why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin corresponds to the clock center. The clock was painted two colors as is shown in the picture:

The picture shows only the central part of the clock. This coloring naturally extends to infinity.

The balls can be taken to be points on the plane. Your task is to find the color of the area, damaged by the given ball.

All the points located on the border of one of the areas have to be considered painted black.

输入格式

The first and single line contains two integers $ x $ and $ y $ — the coordinates of the hole made in the clock by the ball. Each of the numbers $ x $ and $ y $ has an absolute value that does not exceed $ 1000 $ .

输出格式

Find the required color.

All the points between which and the origin of coordinates the distance is integral-value are painted black.

样例 #1

样例输入 #1

-2 1

样例输出 #1

white

样例 #2

样例输入 #2

2 1

样例输出 #2

black

样例 #3

样例输入 #3

4 3

样例输出 #3

black

代码如下

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

int x, y, r;
int main(){
    scanf("%d%d",&x,&y);
    r = sqrt(x * x + y * y);
    if((r % 2 == 0 && x * y >= 0) || (r % 2 && x * y <= 0) || r * r == x * x + y * y)
        printf("black\n");
    else
        printf("white\n");
    return 0;
}

五、Translation

题面翻译

题面描述

Berland 和 Birland 两地均有各自的语言,Berlandish 和 Birlandish。V 是一个翻译员,负责将 Berlandish 翻译成 Birlandish。将 Berlandish 翻译成 Birlandish 其实非常简单,只需把这个单词倒过来。比如单词code翻译过来就是edoc。但是粗心的 V 还是会犯一些错误。现在请你帮她判断一下他翻译的是否正确。

输入格式

两行,分别是一个 Berlandish 单词和 V 翻译的 Birlandish 单词。单词中所有字母均为小写拉丁字母(其实就是英文字母);单词长度均不超过 100 100 100 字符,单词中不包含任何多余空格。

输出格式

一行,如果 V 的翻译是正确的,输出YES。否则输出NO

题目描述

The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it’s easy to make a mistake during the «translation». Vasya translated word $ s $ from Berlandish into Birlandish as $ t $ . Help him: find out if he translated the word correctly.

输入格式

The first line contains word $ s $ , the second line contains word $ t $ . The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.

输出格式

If the word $ t $ is a word $ s $ , written reversely, print YES, otherwise print NO.

样例 #1

样例输入 #1

code
edoc

样例输出 #1

YES

样例 #2

样例输入 #2

abb
aba

样例输出 #2

NO

样例 #3

样例输入 #3

code
code

样例输出 #3

NO

代码如下

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




int main()
{
	char n[1001];
	scanf("%s",&n);
	
	char m[1001];
	scanf("%s",&m);
	
	for(int i = 0;i < strlen(n);i++)
	{
		if(n[i] != m[strlen(n) -i - 1])
		{
			printf("NO\n");
			return 0;
		}
	}
	
	printf("YES\n");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值