照著題目的公式算出來找出最小的那個計畫即可。
C++(0.000)
/*******************************************************/
/* UVa 12157 Tariff Plan */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2018/10/01 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
int T;
while(scanf("%d", &T) != EOF){
for(int caseNumber = 1 ; caseNumber <= T ; ++caseNumber){
int N;
scanf("%d", &N);
int mileTotalCost = 0, juiceTotalCost = 0;
for(int i = 0 ; i < N ; ++i){
int duration;
scanf("%d", &duration);
mileTotalCost += (duration / 30 + 1) * 10;
juiceTotalCost += (duration / 60 + 1) * 15;
}
printf("Case %d: ", caseNumber);
if(mileTotalCost <= juiceTotalCost) printf("Mile ");
if(juiceTotalCost <= mileTotalCost) printf("Juice ");
printf("%d\n", min(mileTotalCost, juiceTotalCost));
}
}
return 0;
}
[…] #UVa:12157-Tariff Plan […]