题意是说一个人喝酒 有两种办法 买塑料瓶的 a块钱 喝了就没了 或者是买玻璃瓶的b块钱 喝完还能卖了瓶子c块钱 求最多能喝多少瓶

在开始判断一次 a与b-c的关系 即两种方式喝酒的成本

如果a<=b-c 那么直接全部买塑料瓶就行了 没必要买玻璃瓶 因为麻烦 而且会出现钱不够b却够b-c这种情况 很麻烦

如果a>b-c  也就是说买玻璃瓶更省一些 就应当先买玻璃瓶的 不行了再尝试塑料瓶

第一种情况只做一次除法就够了

第二种情况 如果用while循环(n>b)来做 会超时在test48...醉倒在梨花风凉的夜晚..

在这里有一个技巧 当n>b时 先让n-=b 这时候留的钱可以进行无限次循环喝酒成本  即tot=(n-b)/(b-c)+1  加的一是一开始减去的b的次数 然后再求之后能不能喝塑料瓶

英语好伤..读题耗费了好久...

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
long long int a,b,c;
long long int n;
int xiao;
int main(){
while(~scanf("%lld",&n))
{
scanf("%lld%lld%lld",&a,&b,&c);
long long int ans=0;
if(a<=(b-c))
{
while(n>=a)
{
long long int tot=n/a;
ans+=tot;
n-=tot*a;
}
printf("%lld\n",ans);
}
else if(a>(b-c))
{
long long int yu=b-c;
if(n>=b)
{
ans+=(n-b)/ yu+1;
}
n-=ans*yu;
while(n>=a)
{
long long int tot=n/a;
ans+=tot;
n-=tot*a;
}
printf("%lld\n",ans);
} }
}

  

CodeForces 625A 思维的更多相关文章

  1. Codeforces 424A (思维题)

    Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  2. Codeforces 1060E(思维+贡献法)

    https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...

  3. Queue CodeForces - 353D (思维dp)

    https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...

  4. 【15.07%】【codeforces 625A】Guest From the Past

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  5. codeforces 1244C (思维 or 扩展欧几里得)

    (点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...

  6. 【CodeForces 625A】Guest From the Past

    题 题意 一升奶可以花费a元,也可以话b元买然后获得c元,一开始有n元,求最多买多少升奶. 分析 贪心,如果b-c<a,且n≥b,那就买b元的,n先减去b再看看够买多少瓶,然后再+1瓶,余款再购 ...

  7. CodeForces - 417B (思维题)

    Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

  8. CodeForces - 417A(思维题)

    Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit  ...

  9. CodeForces 625A Guest From the Past

    贪心水题 #include <stdio.h> #include <algorithm> #include <string.h> #include <queu ...

随机推荐

  1. [Android Pro] RecyclerView实现瀑布流效果(二)

    referece to : http://blog.csdn.net/u010687392 在上篇中我们知道RecyclerView中默认给我们提供了三种布局管理器,分别是LinearLayoutMa ...

  2. IDE整理

    1.eclipse 下载地址:http://www.eclipse.org/downloads/     2.myeclipse 下载地址:http://www.myeclipseide.com/mo ...

  3. tuple元组(C++11及以后,如C++14)

    类tuple与array最本质的区别当数tuple元组元素类型可以不一样,而统一数组array的元素类型必须一样. 本文主要举例: tuple_size Example 123456789101112 ...

  4. nginx增加ssl服务方法

    1.将申请到的ssl加密证书文件拷贝到nginx的conf目录下 如:server.pem.server.key 2.vim nginx.conf 例子: server { listen 443 ss ...

  5. Java Hour 34 Weather ( 7 ) struts2 – validate

    有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. Hour 34 Form Validation 一般Form 提交都有验证的, ...

  6. Oracle11完全卸载方法 deinstall.bat如何用以及如何删除oracle注册表

    转自:http://blog.sina.com.cn/s/blog_68fe7e15010100an.html 之前因为不知道偶电脑是因为安装了oracle后,才导致的长达两周的开机速度要足足10分钟 ...

  7. Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学

    C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...

  8. node Later定时任务

    var later = require('later'); later.date.localTime(); var basic = {h: [15], m: [40], s: [0]}; var co ...

  9. 【HTML5】地理定位

    <!DOCTYPE html> <html> <body> <p id="demo">点击这个按钮,获得您的坐标:</p> ...

  10. Jquery 文档的各种高度和宽度

    $(document).ready(function() { alert($(window).height()); //浏览器时下窗口可视区域高度 alert($(document).height() ...