#UVa:12157-Tariff Plan

照著題目的公式算出來找出最小的那個計畫即可。

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;
}
廣告

1 Comment

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料

%d 位部落客按了讚: