本文分享的必刷题目是从蓝桥云课洛谷AcWing等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。

欢迎大家订阅我的专栏:算法题解:C++与Python实现

附上汇总贴:算法竞赛备考冲刺必刷题(C++) | 汇总


【题目来源】

AtCoder:A - Plant Growth Record

【题目描述】

Takahashi is growing N N N plants.

Currently, the height of the i i i-th plant is A i A_i Ai millimeters. Each plant grows by a fixed length per day, and the i i i-th plant grows by B i B_i Bi millimeters per day.

Find the total height of all N N N plants, in millimeters, after D D D days from now.

It is guaranteed that the answer does not exceed 2 × 10 16 2 \times 10^{16} 2×1016.

【输入】

N N N D D D
A 1 A_1 A1 B 1 B_1 B1
A 2 A_2 A2 B 2 B_2 B2
⋮ \vdots
A N A_N AN B N B_N BN

The first line contains the number of plants N N N and the number of elapsed days D D D, separated by a space.

The ( i + 1 ) (i + 1) (i+1)-th line ( 1 ≤ i ≤ N 1 \leq i \leq N 1iN) contains the current height A i A_i Ai of the i i i-th plant and its daily growth amount B i B_i Bi, separated by a space.

高桥正在培育 N N N 株植物。

目前,第 i i i 株植物的高度是 A i A_i Ai 毫米。每株植物每天生长固定的长度,第 i i i 株植物每天生长 B i B_i Bi 毫米。

求从现在起 D D D 天后,所有 N N N 株植物的总高度(单位为毫米)。

可以保证答案不超过 2 × 10 16 2 \times 10^{16} 2×1016

【输出】

Print on a single line the total height of all N N N plants after D D D days from now, in millimeters.

【输入样例】

3 5
10 2
20 3
15 1

【输出样例】

75

【算法标签】

#模拟

【代码详解】

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, d, ans;  // 物品数量、单位价格、答案

signed main()
{
    cin >> n >> d;  // 读入n和d
    for (int i=1; i<=n; i++)  // 处理每个物品
    {
        int a, b;  // 物品的两个参数
        cin >> a >> b;  // 读入a和b
        ans += a + d*b;  // 计算总价值
    }
    cout << ans << endl;  // 输出结果
    return 0;
}

【运行结果】

3 5
10 2
20 3
15 1
75
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐