天天看點

AtCoder題解 —— AtCoder Beginner Contest 186 —— A - Brick題目相關題解報告

題目相關

題目連結

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;
}
           
AtCoder題解 —— AtCoder Beginner Contest 186 —— A - Brick題目相關題解報告

時間複雜度

O(1)。

空間複雜度

O(1)。

繼續閱讀