题解:AtCoder AT_awc0083_a Plant Growth Record
本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。
欢迎大家订阅我的专栏:算法题解:C++与Python实现!
附上汇总贴:算法竞赛备考冲刺必刷题(C++) | 汇总
【题目来源】
AtCoder:A - Plant Growth Record
【题目描述】
Takahashi is growingN NNplants.
Currently, the height of thei ii-th plant isA i A_iAimillimeters. Each plant grows by a fixed length per day, and thei ii-th plant grows byB i B_iBimillimeters per day.
Find the total height of allN NNplants, in millimeters, afterD DDdays from now.
It is guaranteed that the answer does not exceed2 × 10 16 2 \times 10^{16}2×1016.
【输入】
N NND DD
A 1 A_1A1B 1 B_1B1
A 2 A_2A2B 2 B_2B2
⋮ \vdots⋮
A N A_NANB N B_NBN
The first line contains the number of plantsN NNand the number of elapsed daysD DD, separated by a space.
The( i + 1 ) (i + 1)(i+1)-th line (1 ≤ i ≤ N 1 \leq i \leq N1≤i≤N) contains the current heightA i A_iAiof thei ii-th plant and its daily growth amountB i B_iBi, separated by a space.
高桥正在培育N NN株植物。
目前,第i ii株植物的高度是A i A_iAi毫米。每株植物每天生长固定的长度,第i ii株植物每天生长B i B_iBi毫米。
求从现在起D DD天后,所有N NN株植物的总高度(单位为毫米)。
可以保证答案不超过2 × 10 16 2 \times 10^{16}2×1016。
【输出】
Print on a single line the total height of allN NNplants afterD DDdays from now, in millimeters.
【输入样例】
3 5 10 2 20 3 15 1【输出样例】
75【算法标签】
#模拟
【代码详解】
#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintn,d,ans;// 物品数量、单位价格、答案signedmain(){cin>>n>>d;// 读入n和dfor(inti=1;i<=n;i++)// 处理每个物品{inta,b;// 物品的两个参数cin>>a>>b;// 读入a和bans+=a+d*b;// 计算总价值}cout<<ans<<endl;// 输出结果return0;}【运行结果】
3 5 10 2 20 3 15 1 75