ZOJ 3948 - Marjar Cola
让我回想起了小学的时候,空瓶换饮料还能向别人借一个空瓶喝了再还回去的神奇问题……
开始时思考,特判一下a=1或者b=1的情况为INF就可以了,然后发现2 2 1 2这样的样例也是能够喝到无穷多瓶饮料的。
所以干脆直接做循环,每次循环模拟换了饮料然后喝掉的情形,如果发现喝完空瓶子不减少或者瓶盖子不减少,那显然是能喝不知道多少瓶饮料了,就直接输出INF。
#include<cstdio>
int x,y,a,b,cnt;
bool flag;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&x,&y,&a,&b);//x空瓶 or y瓶盖换满瓶 ; 现有a空瓶,b瓶盖
cnt=;
flag=;
while(a>=x || b>=y)
{
int now_a=a,now_b=b;
if(a>=x)
{
int c=a/x;
a=a%x+c;
b+=c;
cnt+=c;
}
if(b>=y)
{
int c=b/y;
b=b%y+c;
a+=c;
cnt+=c;
}
if(a>=now_a && b>=now_b)
{
printf("INF\n");
flag=;
break;
}
}
if(flag) printf("%d\n",cnt);
}
}
ZOJ 3948 - Marjar Cola的更多相关文章
- ZOJ - 3948 Marjar Cola 【循环】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3948 题意 用 x 个 瓶身 可以 换 一瓶饮料 用 y 个 瓶 ...
- 2017浙江省赛 B - Problem Preparation ZOJ - 3959
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 题目: It's time to prepare the pr ...
- 2017 浙大校赛 [Cloned]
https://vjudge.net/contest/285902#overview A.Marjar Cola #include <bits/stdc++.h> using namesp ...
- The 17th Zhejiang University Programming Contest Sponsored by TuSimple A
Marjar Cola Time Limit: 1 Second Memory Limit: 65536 KB Marjar Cola is on sale now! In order to ...
- ZOJ 3860: - Find the Spy
3860 - Find the Spy Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- ZOJ 3819 Average Score(平均分)
Description 题目描述 Bob is a freshman in Marjar University. He is clever and diligent. However, he is n ...
- ZOJ 3946.Highway Project(The 13th Zhejiang Provincial Collegiate Programming Contest.K) SPFA
ZOJ Problem Set - 3946 Highway Project Time Limit: 2 Seconds Memory Limit: 65536 KB Edward, the ...
- ZOJ 2819 Average Score 牡丹江现场赛A题 水题/签到题
ZOJ 2819 Average Score Time Limit: 2 Sec Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge ...
- ZOJ 3962 Seven Segment Display 16进制的八位数加n。求加的过程中所有的花费。显示[0,F]有相应花费。
Seven Segment Display Time Limit: Seconds Memory Limit: KB A seven segment display, or seven segment ...
随机推荐
- Linux服务器部署 Elasticsearch 成功,本机却访问不了
Elasticsearch版本: elasticsearch- 服务器版本: CentOS release 6.8 (Final) 问题: Linux服务器上部署了 Elasticsearch 5.5 ...
- Dubbo -- 系统学习 笔记 -- 示例 -- 多注册中心
Dubbo -- 系统学习 笔记 -- 目录 示例 想完整的运行起来,请参见:快速启动,这里只列出各种场景的配置方式 多注册中心 可以自行扩展注册中心,参见:注册中心扩展 (1) 多注册中心注册 比如 ...
- 标签a点击以后,5秒内禁止点击,5秒后激活
方法1:利用bootstrap里面的类disabled,禁止链接 <a href='javascript:onHref()' id="test">点击</a> ...
- 【GIS】使用GDAL为Leaflet切图
一.参考资料 https://commenthol.github.io/leaflet-rastercoords/ https://github.com/commenthol/gdal2tiles-l ...
- nginx_lua_waf 部署、测试记录
ngx_lua_waf ngx_lua_waf是一个基于lua-nginx-module(openresty)的web应用防火墙 源码:https://github.com/loveshell/ngx ...
- SaltStack 批量分发文件
这里演示如何将 salt-master 上的文件批量分发到多台 salt-minion,步骤如下: [root@localhost ~]$ cat /srv/salt/top.sls # 先定义入口配 ...
- N76E003的学习之路(一)
N76E003是8051内核的一款单片机MCU,它提供丰富的特殊功能模块,包括: 1KRAM其中包括256字节SRAM,768字节XRAM. 最多可达18个标准管脚. 两组标准16位定时器/计数器:定 ...
- js控制滚动条的位置以及隐藏滚动条
document.documentElement.style.overflow = 'hidden'; //隐藏横竖滚动条 window.scrollTo(0,document.body.scroll ...
- 使用CreateProcess创建新的process 并返回process运行结束返回值
转自:http://blog.csdn.net/zgl7903/article/details/5975284 转载这篇主要是记住:获得create的新进程运行结束时的返回值的方法 如下: #in ...
- Linux学习(二)
Linux进程管理 每个 Linux 命令都与系统中的程序对应,输入命令,Linux 就会创建一个新的进程.例如使用 ls 命令遍历目录中的文件时,就创建了一个进程.简而言之,进程就是程序的实例. 创 ...