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 ...
随机推荐
- 7 -- Spring的基本用法 -- 6... Spring 3.0 提供的Java配置管理
7.6 Spring 3.0 提供的Java配置管理 Spring 允许使用Java类进行配置管理,可以不使用XML来管理Bean,以及Bean之间的依赖关系. Interface :Person p ...
- ubuntu13.04 搭建 Nginx + PHP + PHP-FPM + Mysql (lnmp) 环境
Nginx 是一个轻量级,以占用系统资源少,运行效率而成为web服务器的后起之秀,国内现在很多大型网站都以使用nginx,包括腾讯.新浪等大型信息网站,还有淘宝网站使用的是nginx二次开发的web服 ...
- 简单思考 如何用PHP输出本周的周三日期
简单思考 如何用PHP输出本周的周三日期?比如今天2017-10-31 计算本周周三应该是2017-11-01 自己动脑筋想一想,然后给我留言或者评论
- iOS 添加Resource bundle target(静态库中使用图片等资源)
一.首先将资源文件打包成bundle 新建工程:File -> New -> Project... -> OS X -> Framework & Library -&g ...
- mongodb int字段的一个小坑
在使用 php mongodb 搜索时,如果字段类型用 int,则使用 php 搜索时一定要把数值转换成整型来搜索,用字符串类型的数字搜索是没有结果的!!!! $condition = ['membe ...
- 如何使用 SSH 连接 VMWare 虚拟机中的 Ubuntu
环境:VMWare Player 5.0.2,Ubuntu 13.10 VMWare共有3种网络连接模式,分别是: 1. bridged(桥接模式):虚拟机将直接连接到物理局域网,使自身独立于宿主机 ...
- code_blocks 使用操作手册
38 39 编译以上程序,产生如下提示信息. 如此简 ...
- JS 实现拖动效果
<html> <body style="margin:0px;"> <script src="http://ajax.googleapis. ...
- PHP中常见问题总结
[1]页面之间无法传递变量 get,post,session在最新的php版本中自动全局变量是关闭的,所以要从上一页面取得提交过来得变量要使用$_GET['foo'],$_POST['foo'],$_ ...
- GitHub----初学习(一)
刚开始学习GitHub,在这借鉴一下别人的总结,http://youngxhui.github.io/2016/05/03/GitHub-for-Windows%E4%BD%BF%E7%94%A8%E ...