codeforces #342 div 2 A. Guest From the Past

http://codeforces.com/contest/625/problem/A 题意:有n块钱,塑料瓶饮料a元一瓶,玻璃瓶饮料b元一瓶,退还玻璃瓶可以得到c元。问最多能买多少瓶饮料。 思路:贪心。如果塑料瓶比玻璃瓶的实际价格便宜,那么一定买塑料瓶的,否则先买玻璃瓶,再用塑料瓶填。注意一些边界的判断。。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月07日 星期日 17时02分32秒
 4File Name :code/cf/#342/A.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33LL a,b,c,n;
34int main()
35{
36	#ifndef  ONLINE_JUDGE 
37//	freopen("code/in.txt","r",stdin);
38  #endif
39
40	cin>>n;
41	cin>>a>>b>>c;
42	LL ans=0;
43	if (b-c>a)
44	{
45	    ans = n/a;
46	}
47	else
48	{
49	    while (n-b>=b-c)
50	    {
51		LL tmp = (n-b)/(b-c);
52		ans += tmp;
53		n-=tmp*(b-c);
54
55	    }
56
57	    while (n>=b)
58	    {
59		LL tmp =n/b;
60		ans +=tmp;
61		n-=tmp*(b-c);
62	    }
63
64
65	ans +=n/a;
66	}
67
68	cout<<ans<<endl;
69
70  #ifndef ONLINE_JUDGE  
71  fclose(stdin);
72  #endif
73    return 0;
74}