当前位置: 代码迷 >> 综合 >> Gym - 101911J - Buying a TV Set
  详细解决方案

Gym - 101911J - Buying a TV Set

热度:92   发布时间:2024-02-24 12:08:19.0

题目

传送门
在这里插入图片描述

Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063

题意:给出四个数a,b,x,y,要挑选的电视机的比例为x/y且x不能大于a,y不能大于b,问:能选几台不同的电视机

思路:先约分从最小的符合比例的电视机开始挑即可

AC code

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<sstream>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
ll a[210000];
int main()
{
    ll a,b,x,y;
cin>>a>>b>>x>>y;ll c=__gcd(x,y);//最大公约数x/=c,y/=c;
ll p=a/x,q=b/y;
ll g=min(p,q);
printf("%lld\n",g);
}