Codeforces Round #342 (Div. 2)(A)贪心,数学
来源:互联网 发布:海康提示网络不可达 编辑:程序博客网 时间:2024/05/16 18:25
题意:你有n元钱,你有2种选择
1.使用每升a元买一瓶塑料牛奶
2使用每升b元买一瓶玻璃牛奶,每个玻璃瓶可以退回c元钱
问最多可以买多少升?
题解:如果b-c<=a,显然买b,那么只要n>=b,我们买b类绝对是不会亏的,我们尽可能的买b类后,再去买a类,否则直接买a类
我开始怎么都过不了样例,于是写了个DFS过了,最后极限数据还是超时了。
#include <set>#include <map>#include <list> #include <cmath> #include <queue> #include <vector>#include <cstdio> #include <string> #include <cstring>#include <iomanip> #include <iostream> #include <sstream>#include <algorithm>#define LL unsigned long long using namespace std;#define N 100000#define inf 0x3f3f3f3f3f3f3f3fLL n,a,b,c;LL ans;int main(){#ifdef CDZSCfreopen("i.txt","r",stdin);#endifwhile(~scanf("%lld",&n)){ans=0;scanf("%lld%lld%lld",&a,&b,&c);if(n>=b&&b-c<=a){LL sum=((n-b)/(b-c)+1);n-=sum*(b-c);ans+=sum;}ans+=n/a;printf("%lld\n",ans);}return 0;}
0 0
- Codeforces Round #342 (Div. 2)(A)贪心,数学
- Codeforces Round #236 (Div. 2)A(贪心、数学)
- Codeforces Round #260 (Div. 2) A (贪心)
- Codeforces Round #111 (Div. 2) A Twins (贪心)
- Codeforces Round #279 (Div. 2)---A. Team Olympiad (贪心)
- Codeforces Round #303 (Div. 2) A - Equidistant String(贪心)
- Codeforces Round #202 (Div. 2)(A)贪心
- Codeforces Round #311 (Div. 2)(A)贪心
- Codeforces Round #188 (Div. 2) A(数学划分)
- Codeforces Round #349 (Div. 2)-A. Pouring Rain(数学)
- Codeforces Round #392 (Div. 2) A(水)B(水、模拟) C(数学) D(贪心)
- Codeforces Round #342 (Div. 2)-A. Guest From the Past(数学)
- Codeforces Round #384 (Div. 2)(数学)
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- Codeforces Round #342 (Div. 2)(B)贪心
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A(贪心)
- Codeforces Round #199 (Div. 2) A ( 简单贪心 )
- Codeforces Round #340 (Div. 2)-A. Elephant(贪心)
- POJ 2240_Arbitrage
- utf8解决JSP中文乱码问题
- linux习惯每天一个命令之mount命令
- Hibernate细节
- 今天是春节
- Codeforces Round #342 (Div. 2)(A)贪心,数学
- UVA 11400_ Lighting System Design
- Codeforces Round #342 (Div. 2)(B)贪心
- 即使是新春
- assets下的文件都包装成Drawable对象
- Codeforces Round #342 (Div. 2)(C)构造
- win7之替换开机登录背景图
- hdu3001 Travelling(状态压缩dp,三进制)
- 如何获取微信红包照片的原始清晰图片