14088: 【原4088】运动校园
题目
题目描述
author: Vegw 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4088
Description
运动世界校园的截止日期临近,但蓓贝距离完成里程目标还有一定差距,她需要你的帮助。
蓓贝共有三种运动方式:走路, 慢跑, 快跑
可认为走路不消耗体力,但慢跑和快跑均有不同程度的体力消耗,三者切换不需要时间。同时蓓贝不希望在任一一种跑步过程中发生中断,即一旦采取某种跑步方式,蓓贝会维持当前运动状态运动\(k*a_{i}, k \in \mathbb N^{+}\)个距离,其中\(a_{i}(i = 1, 2)\)为给定的两种跑步方式各自的单次最小里程。
蓓贝希望以最小体力消耗完成里程目标,求该值。
Input Format
输入数据包括
第1行:三个数值, 剩余总里程 f, 剩余时间 T, 步行速度 t0 (运动1个单位长度耗费t0时间)
第2 ~ 3行:每行三个数值,分别为单次最小跑步里程\(a_{i}\),运动速度\(t_{i}\)(定义同步行速度),单次耗费体力值\(p_{i}\)。
Output Format
一行:一个值,如果蓓贝能够在截止日期前完成里程目标,输出最小体力耗费,否则输出 -1;
Sample Input1
3 14 5
2 4 9
7 6 11
Sample Output1
9
Sample Input2
3 15 5
2 4 9
7 6 11
Sample Output2
0
FineArtz's solution
/* 运动校园 */
#include <iostream>
#include <cmath>
using namespace std;
int main(){
long long f, T, t0, a1, t1, p1, a2, t2, p2;
cin >> f >> T >> t0;
cin >> a1 >> t1 >> p1;
cin >> a2 >> t2 >> p2;
long long c1 = -a1 * (t1 - t0), c2 = -a2 * (t2 - t0), n = -T + f * t0;
long long ans = 10000000000000000ll, y = 0, z = 0;
if (n <= 0){
cout << "0" << endl;
return 0;
}
if (c1 <= 0 && c2 <= 0){
cout << "-1" << endl;
return 0;
}
if (c1 <= 0){
z = n / c2;
if (n % c2 != 0) ++z;
cout << z * p2 << endl;
return 0;
}
if (c2 <= 0){
y = n / c1;
if (n % c1 != 0) ++y;
cout << y * p1 << endl;
return 0;
}
for (long long y = 0; ; ++y){
long long t = n - c1 * y;
if (t <= 0) z = 0;
else{
z = t / c2;
if (t % c2 != 0) ++z;
}
long long p = y * p1 + z * p2;
if (ans > p) ans = p;
if (t <= 0) break;
}
if (ans == 10000000000000000ll)
cout << "-1" << endl;
else
cout << ans << endl;
return 0;
}
ligongzzz's solution
#include "iostream"
using namespace std;
int main() {
int f, T, t0;
int a1, t1, p1;
int a2, t2, p2;
cin >> f >> T >> t0 >> a1 >> t1 >> p1 >> a2 >> t2 >> p2;
//判断输入是否正常
if(double(p1)/double(a1))
return 0;
}