14204: 【原4204】小远吃水果
题目
题目描述
author: Pikachu 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4204
小远吃水果
题目描述
还记得去年东方绿洲的故事吗,最后小致和小远的小组获得了相当不错的成绩。面对今年的小故事课,小致和小远决定再一次和小源小思组队。某个晴朗的下午,他们相聚在咖啡厅。小远因为课太多了没吃午饭。小组同学准备一起给小远买一些水果。于是他们一起来到了商店。
对于第$i$种水果,小组同学需要购买$V_i$斤,而第$i$种水果,1斤花费$a_i$,2斤花费$b_i$元。由于水果太多了,请你帮助漂亮的小远同学算一算,他们最少要花费多少钱购买每一种水果呢?
输入格式
输入数据有若干行,第一行为水果的种类数$q$。
从第二行到第$q+1$行,每行3整数分别代表第$i$种水果,需要购买$V_i$斤,1斤花费$a_i$,2斤花费$b_i$元。
输出格式
输出$q$行,每一行一个整数,为对于每一种水果最少需要资金。
样例输入
3
10 1 3
7 3 2
1000000000000 42 88
样例输出
10
9
42000000000000
数据规模
对于$20\%$的数据有$q=1$。
对于$100\%$的数据有$q\leq 1000, a_i \leq 10^9, b_i\leq 10^9$。
BugenZhao's solution
//
// Created by BugenZhao on 2019/3/18.
//
// 辣鸡
#include <iostream>
#include <algorithm>
using namespace std;
static const auto _____ = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
return nullptr;
}();
using ll=long long;
int main() {
int q;
cin >> q;
while (q--) {
ll v, a, b;
cin >> v >> a >> b;
ll ans = 0;
if (a * 2 <= b) {
ans = v * a;
} else {
if (v % 2 == 0) {
ans = v / 2 * b;
} else {
ans = v / 2 * b + a;
}
}
cout << ans << endl;
}
return 0;
}
skyzh's solution
#include <iostream>
using namespace std;
int main() {
int q;
long long amount, s, d;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
cin >> amount >> s >> d;
if (s * 2 <= d) {
cout << s * amount << endl;
} else {
cout << (d * (amount / 2)) + (amount % 2) * s << endl;
}
}
return 0;
}