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