题意是说一个人喝酒 有两种办法 买塑料瓶的 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] 内容提供者ContentProvider的基本使用

    一.ContentProvider简介 当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就可以向其他应用共享其数据.ContentProvider为存储和获取数据提 ...

  2. Ubuntu下自动挂载分区

    参考文章:http://feierky.iteye.com/blog/1998602 1.查看分区的UUID sudo blkid /dev/sda1: UUID="3526b254-390 ...

  3. Git Server & Git Hook

    http://ju.outofmemory.cn/entry/16893 我喜欢 github,我现在的个人代码全部是托管在上面了,但是一些公司或者某些项目不适合放入github中,你希望能有一个完全 ...

  4. async/await 异步编程

    前言 最近在学习Web Api框架的时候接触到了async/await,这个特性是.NET 4.5引入的,由于之前对于异步编程不是很了解,所以花费了一些时间学习一下相关的知识,并整理成这篇博客,如果在 ...

  5. Mac下搭建go语言开发环境

    一.下载安装go 到墙内下载go的安装包: http://www.golangtc.com/download 点击安装包然后进行安装 二.配置 1.查看环境 go version 2.安装完sdk之后 ...

  6. poj 1811 大数分解

    模板 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> ...

  7. Gym 100650H Two Ends DFS+记忆化搜索

    Problem H: Two EndsIn the two-player game “Two Ends”, an even number of cards is laid out in a row. ...

  8. cocos2dx游戏开发——捕鱼达人mini版学习笔记(二)——MainMenu的搭建

    一.创建文件~ MainMenuScene.h   MainMenuScene.cpp   MainMenuLayer.h   MainMenuLayer.cpp 那个场景的搭建就不多说了,那个我的打 ...

  9. Android Studio 1.0首次安装遇到的问题,无法下载SDK

    相信,在安装Android Studio的过程中会遇到很多问题,特别是第一次启动下载不了sdk.郁闷了吧. 可以去官网下载,也可以点击这里下载Android Studio和sdk. 一.不下载SDK启 ...

  10. lr参数化——500户并发迭代1次 循环取5条数据

    lr参数化——500户并发迭代1次 循环取5条数据 比如vuser1.vuser2.vuser3..........,vuser500 shuju1,shuju2,shuju3,shuju4,shuj ...