CodeForces 625A 思维
题意是说一个人喝酒 有两种办法 买塑料瓶的 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 思维的更多相关文章
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- Codeforces 1060E(思维+贡献法)
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...
- Queue CodeForces - 353D (思维dp)
https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...
- 【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 ...
- codeforces 1244C (思维 or 扩展欧几里得)
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...
- 【CodeForces 625A】Guest From the Past
题 题意 一升奶可以花费a元,也可以话b元买然后获得c元,一开始有n元,求最多买多少升奶. 分析 贪心,如果b-c<a,且n≥b,那就买b元的,n先减去b再看看够买多少瓶,然后再+1瓶,余款再购 ...
- CodeForces - 417B (思维题)
Crash Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status ...
- CodeForces - 417A(思维题)
Elimination Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- CodeForces 625A Guest From the Past
贪心水题 #include <stdio.h> #include <algorithm> #include <string.h> #include <queu ...
随机推荐
- [SVN(ubuntu)] ubuntu使用svn
转载自:http://lee2013.iteye.com/blog/1058047 SVN作为日常开发中不可缺少的工具,Ubuntu下的SVN安装十分简单,sudo apt-get install s ...
- Ruby备忘
- WebService之CXF框架
本文主要包括以下内容 ant工具的使用 利用cxf实现webservice cxf与spring整合 ajax访问webservice ant 工具 1.为什么要用到ant这个工具呢? Ant做为一种 ...
- Android之webView入门
WebView可以使得网页轻松的内嵌到app里,还可以直接跟js相互调用. webview有两个方法:setWebChromeClient 和 setWebClient setWebClient:主要 ...
- SSH 超时断开连接解决办法
配置服务器端: vi /etc/ssh/sshd.conf ClientAliveInterval 120 #以秒为单位(可以改大些) ClientAliveCountMax 0 #发现客户端没有相应 ...
- 在Windows中使用MinGW编译X264
转自:http://www.cnblogs.com/xiongjiaji/archive/2012/06/08/2541265.html 参考:http://ayobamiadewole.com/Bl ...
- 小甲鱼PE详解之区块表(节表)和区块(节)续(PE详解05)
这一讲我们结合实例来谈谈区块表的定义以及各个属性的含义. 首先,我们先用之前学过的一点知识在二进制文件中手动翻找区块表,这样做的好处是可以使你很快的对PE结构牢记于心.学来的东西就是能用的东西,不能用 ...
- MATLAB学习笔记(三)——程序设计
(一)M文件 一.概述 1.自己的体会就是把相应的操作写成一个文本文件,这样子的话方便进行修改(记事本就行了),又可以达到封装的目的,当然我发现2014a版本的Matlab貌似已经采用的面向对象的设计 ...
- c++工程vs导入工程时发生LNK1207
I have installed VS 2012 , but i have VS 2010 also. After I open VS 2010 projects with VS 2012 and ...
- 使用Spring的jdbcTemplate进一步简化JDBC操作
先看applicationContext.xml配置文件: <?xml version="1.0" encoding="UTF-8"?> <b ...