竹園論壇

標題: Q11689 - Soda Surpler [打印本頁]

作者: HSCHE    時間: 2014-5-6 14:48
標題: Q11689 - Soda Surpler
Tim 是一個非常愛喝汽水的人。由於他沒有錢,所以他要喝汽水的唯一方法就是收集空汽水瓶子,然後拿去回收換取錢再去買新汽水來喝。除了他自己喝完的空瓶子,Tim也會到街上去收集別人喝完的空瓶子。有一天,他非常的渴,他要盡可能的喝汽水,直到他得不到任何一瓶為止。
Input
輸入的第1列有一個整數N,代表以下有多少組測試資料。
每組測試資料1列,含有 3 個整數  e,f,c 。e(0 <=  e < 1000)代表Tim一開始擁有的空瓶子數目,f(0 <=  f < 1000)代表Tim在這一天他在街上收集到的空瓶子數目,c(1 <  c < 2000)代表多少個空瓶子可以換一瓶新的汽水。
請參考Sample Input。
Output
對每一組測試資料輸出一列,代表 Tim 可以喝到多少瓶汽水。
Sample InputSample Output
2
9 0 3
5 5 2

4
9




在此附上題目連結
UVA: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2736
LUCKY CAT: http://luckycat.kshs.kh.edu.tw/homework/q11689.htm
解題感想:這題簡單,使用迴圈,應該可以輕鬆解出
AC CODE:

#include<iostream>
  • #include<cstdio>
  • #include<cstring>
  • #include<cmath>
  • #include<stack>
  • #include<vector>
  • using namespace std;
  • int main()
  • {
  •         int a,b,c,s,tot=0,ans=0;
  •         cin>>s;
  •         while(s--)
  •         {
  •                
  •                 cin>>a>>b>>c;
  •                 tot=a+b;
  •                 ans=0;
  •                 while(tot>=c)
  •                 {
  •                         ans+=tot/c;
  •                         tot=tot/c+tot%c;
  •                 }
  •                 cout<<ans<<"\n";
  •         }
  • }







  • 歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2