Codeforces Round #340 (Div. 2)题解

本文提供了Codeforces Round #340 (Div. 2)比赛的题目解析,包括A到E五道题目。A题大象搬家,求大象到达朋友家的最少步数;B题巧克力分块,询问将巧克力分成每块含一个坚果的不同方式;C题浇水花朵,找到最小的水范围覆盖所有花朵;D题多边形路径,找出通过三个点的最短路径段数;E题异或与最爱数字,计算子数组异或和等于特定值的子数组数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Elephant

An elephant decided to visit his friend. It turned out that the elephant’s house is located at point 0 and his friend’s house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend’s house.

Input

The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend’s house.

Output

Print the minimum number of steps that elephant needs to make to get from point 0 to point x.

Sample test(s)

Input
5
Output
1
Input
12
Output
3
Note
In the first sample the elephant needs to make one step of length 5 to reach the point x.
In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.


题意:大象去看它的朋友,大象的家在数轴的原点,朋友的家在x(x>0)的地方,大象一次可以前进1, 2, 3, 4, 5,问大象到达朋友家需要的最少移动次数
简单水题。由于是让求最少的移动次数,所以每次应尽可能走的多,但还不能超过x

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define N 55
const int mm = 1000000007;
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
//  freopen("1.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, ans;
    cin >> x;
    ans = x/5;
    x %= 5;
    ans += x/4;
    x %= 4;
    ans += x/3;
    x %= 3;
    ans += x/2;
    x %= 2;
    ans += x;
    cout << ans;    
    return 0;
}

B. Chocolate

Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.

You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn’t.

Please note, that if Bob doesn’t make any breaks, all the bar will form one piece and it still has to have exactly one nut.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar.
The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.

Output

Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.

Sample test(s)

Input
3
0 1 0
Output
1
Input
5
1 0 1 0 1
Output
4
Note
In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn’t make any breaks.
In the second sample you can break the bar in four ways:
10|10|1
1|010|1
10|1|01
1|01|01


题意:Bob 有一块巧克力条,他希望把这块巧克力条分成若干块,而且每块必须有一个坚果,问有多少种分发?
简单题,但有一个坑。这道题我WA了好几次,每次都是在第七组数据错。到最后才想到,如果全是0,就应该输出0。
思路:先把特殊情况处理了,然后计算相邻两个坚果直接有多少可以划分的地方,然后乘到一起就是最后的结果了

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define N 55
const int mm = 1000000007;
using namespace std;
int
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值