您的位置:首页 > 其它

ZOJ - 3948 Marjar Cola 简单模拟

2017-12-03 19:44 441 查看
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
#define kuaidian ios::sync_with_stdio(0);

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100 + 7, maxd = 1e8;
const ll mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;

int main (){
ios::sync_with_stdio(0);
int t;
cin >> t ;
for (int i = 0 ; i < t; i ++){
int x,y,a,b;
int ans = 0;
cin >> x >> y >> a >> b;
if (x == 1 || y == 1){
cout << "INF" << endl;
}
else if (x == 2 && y ==2 && (a >=2 ||b >=2)){
cout << "INF" <<endl;
}
else {
int res , cnt;
res = a;
cnt = b;
//cout << "++++";
while(res >=x || cnt >= y){
int tmp = 0;
int tmp1 = 0;
tmp += res / x;
res = res - tmp * x;// + tmp;
tmp1 += cnt / y;
cnt = cnt - tmp1 * y;// + tmp1;
//cout << res <<" "<<cnt <<" "<<tmp <<" " << tmp1 <<endl;
res += (tmp + tmp1);
cnt += (tmp + tmp1);
ans =ans +tmp + tmp1;
}
cout << ans <<endl;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: