zoukankan      html  css  js  c++  java
  • 长沙理工大学第十二届ACM大赛-重现赛 J 武藏牌牛奶促销

    链接:https://ac.nowcoder.com/acm/contest/1/J
    来源:牛客网

    武藏牌牛奶促销
    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 131072K,其他语言262144K
    64bit IO Format: %lld
    题目描述
    武藏牌牛奶为了吸引顾客,推出优惠活动,可以使用x个空的瓶身,或者y个瓶盖,去商店换一瓶全新的武藏牌牛奶。注意,一瓶牛奶包含了瓶身和瓶盖。
    现在小萌老师有a个空的瓶身和b个瓶盖,她想喝到尽可能多的牛奶,你知道她到底能喝到多少瓶完整的牛奶吗?
    输入描述:
    多组输入
    每组数据第一行包含4个正整数x y a b(1<=x,y,a,b<=100),意义见题目描述。
    输出描述:
    对于每组数据,输出一行,表示小萌老师最多能喝多少瓶完整的牛奶。如果能喝无数瓶,输出"INF"(不要输出引号)。
    示例1
    输入
    复制
    1 3 1 1
    4 3 6 4
    输出
    复制
    INF
    4
    说明
    对于第二组测试样例,小萌老师有6个空的瓶身和4个瓶盖,她用4个瓶身和3个瓶盖换了2瓶牛奶并喝完,此时她就有4个空的瓶身和3个瓶盖。之后她再换2瓶牛奶并喝完,此时只有2个空的瓶身和2个瓶盖,就无法继续兑换了,所以答案是4

    题意:

    思路:
    把x,y 有一个是1的情况,和x,y都是2的情况判断一下是不是INF 的情况,其他的情况就正常的加加减减算答案就可以了。

    细节见代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <vector>
    #include <iomanip>
    #define ALL(x) (x).begin(), (x).end()
    #define rt return
    #define sz(a) int(a.size())
    #define all(a) a.begin(), a.end()
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define repd(i,x,n) for(int i=x;i<=n;i++)
    #define pii pair<int,int>
    #define pll pair<long long ,long long>
    #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MSC0(X) memset((X), '', sizeof((X)))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define eps 1e-6
    #define gg(x) getInt(&x)
    #define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
    using namespace std;
    typedef long long ll;
    ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
    inline void getInt(int* p);
    const int maxn=1000010;
    const int inf=0x3f3f3f3f;
    /*** TEMPLATE CODE * * STARTS HERE ***/
    
    int main()
    {
        // freopen("D:\code\text\input.txt","r",stdin);
    	//freopen("D:\code\text\output.txt","w",stdout);
    	
    	int x,y,a,b;
    	ll ans;
    	gbtb;
    	while(cin>>x>>y>>a>>b)
    	{
    		ans=0ll;
    		if(x==1||y==1)
    		{
    			if(a>=x||b>=y)
    			{
    				cout<<"INF"<<endl;
    			}else
    			{
    				cout<<0<<endl;
    			}
    		}else if(x==2&&y==2)
    		{
    			if(a>=x||b>=y)
    			{
    				cout<<"INF"<<endl;
    			}else
    			{
    				cout<<0<<endl;
    			}
    		}else
    		{
    			while(a>=x||b>=y)
    			{
    				ans+=a/x;
    				ans+=b/y;
    				int c=a/x+b/y;
    				a%=x;
    				b%=y;
    				a+=c;
    				b+=c;
    			}
    			cout<<ans<<endl;
    		}
    	}
    	
    	
    	
        return 0;
    }
    
    inline void getInt(int* p) {
        char ch;
        do {
            ch = getchar();
        } while (ch == ' ' || ch == '
    ');
        if (ch == '-') {
            *p = -(getchar() - '0');
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 - ch + '0';
            }
        }
        else {
            *p = ch - '0';
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 + ch - '0';
            }
        }
    }
    
    
    
    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    为什么Java不支持多重继承
    thymeleaf生成页面时报错:An error happened during template parsing (template: "class path resource [templates/index.html]")的解决办法
    MySQL操作数据时区分大小写
    java.lang.NoClassDefFoundError: com/jhlabs/image/RippleFilter
    多线程学习系列:(六)线程池基础下
    多线程学习系列:(四)线程同步基础下
    多线程学习系列:(八)Winform中多线程编程基础上
    多线程学习系列:(五)线程池基础上
    多线程学习系列:(七)基于多线程的基本组件
    HTTP头部
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/10996575.html
Copyright © 2011-2022 走看看