ZOJ_3568_Exchange for Cola(水题)

来源:互联网 发布:h3c mac地址绑定ip 编辑:程序博客网 时间:2024/06/07 00:52

Exchange for Cola

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The Cola company is holding a promotional activity that customers can exchange B bottles of Cola with A caps. Now guinao has N caps. Furthermore, guinao can ask mm to borrow him some caps for any times as long as guinao is able to return the caps borrowed after he has used these caps to exchange Cola without buying any other Cola. Please tell guinao how many number of Cola guinao can drink.

Input

This problem contains multiple test cases. Each case contains one line with three numbers NAB, (1 <= N <= 10^9, 1 <= B < A <= 10^9), which have already been mentioned above.

Output

Print exactly one line with the maximal number of Cola guinao can drink by exchanging caps for each test case.

Sample Input

1 2 19 7 2

Sample Output

12

题型:简单题


题意:

        可乐公司做活动,可以用a个瓶盖换b瓶可乐现在guinao有n个盖子,他能够在任何时候跟mm借一些盖子,但是前提是他在换完之后能够将盖子还给mm。问guinao最多能喝到多少瓶可乐。


分析:一次一次模拟,当他还不了借的盖子的时候就break。


代码:

#include<iostream>#include<cstdio>using namespace std;int main(){    long long a,b,n;    long long lend;    long long ans;    while(~scanf("%lld%lld%lld",&n,&a,&b)){        ans=0;        lend=0;        while(1){            if(n<a){                lend=a-n;                n=a;            }            int t=n;            n=n%a+b*(n/a);            if(n>=lend)                ans+=b*(t/a),n-=lend;            else break;        }        printf("%lld\n",ans);    }    return 0;}


原创粉丝点击