2016年7月5日 星期二

Q11150: Cola


https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2091

import java.util.*;

public class Main {

 public static void main(String[] args) {
  Scanner scn = new Scanner(System.in);
  while(scn.hasNext()){
  int n=scn.nextInt(),tot=0;
  tot=n;
  if(n%2==0)n++;
  while(n!=1){
   n-=2;
   tot++;
  }
  System.out.println(tot);
  }
 }
/* 
    題目:Q11150: Cola
    作者:1010
    時間:西元 2016 年 7 月 */

}


困難度 
這題解法非常簡單當有偶數瓶時先+1(借一瓶),進入迴圈3瓶換一瓶所以是-3+1=-2 =>每次-2直到剩餘一瓶

沒有留言:

張貼留言