题目相关
题目链接
AtCoder Beginner Contest 186 A 题,https://atcoder.jp/contests/abc186/tasks/abc186_a。
Problem Statement
We have a truck, which can carry at most N kilograms.
We will load bricks onto this truck, each of which weighs W kilograms. At most how many bricks can be loaded?
Input
Input is given from Standard Input in the following format:
N W
Output
Print an integer representing the maximum number of bricks that can be loaded onto the truck.
Sample 1
Sample Input 1
10 3
Sample Output 1
3
Explaination
Each brick weighs 3 kilograms, so 3 bricks weigh 9 kilograms, and 4 weigh 12 kilograms.
Thus, we can load at most 3 bricks onto the truck that can carry at most 10 kilograms.
Sample 2
Sample Input 2
1000 1
Sample Output 2
1000
Constraints
- 1 ≤ N, W ≤ 1000
- N and W are integers.
题解报告
题目翻译
有一辆卡车,最多可以装 N 公斤。每个砖重量为 W 公斤,问一辆卡车可以装载多少块砖头。
题目分析
ABC 的 A 题依然是这么感人,只要能读懂题目,就可以完成。
一个非常简单的数学题,答案为
⌊
N
W
⌋
\lfloor \frac{N}{W} \rfloor
⌊WN⌋。
向下取整,我们可以直接使用整数除法特性,也可以使用函数 floor() 来实现。
AC 参考代码
//https://atcoder.jp/contests/abc186/tasks/abc186_a
//A - Brick
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//#define __LOCAL
int main() {
#if !defined(__LOCAL)
cin.tie(0);
ios::sync_with_stdio(false);
#endif
int n,w;
cin>>n>>w;
cout<<n/w<<"\n";
return 0;
}
时间复杂度
O(1)。
空间复杂度
O(1)。