水题:CF16C-Monitor
来源:互联网 发布:淘宝牛仔裤哪家好 知乎 编辑:程序博客网 时间:2024/05/17 02:57
Monitor
题目描述
Reca company makes monitors, the most popular of their models is AB999 with the screen size a × b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That\’s why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes x: y, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can\’t be performed.
输入
The first line of the input contains 4 integers — a, b, x and y (1 ≤ a, b, x, y ≤ 2·10^9).
输出
If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.
示例输入
800 600 4 3
1920 1200 16 9
1 1 1 2
示例输出
800 600
1920 1080
0 0
解题心得:
- 一道cf的水题,之前还想多了,写的比较复杂,判断了长和宽,其实没有必要很简单。直接看代码都可以看得懂。但是要注意一点要将x,y的最大公约数给除去,不然得到的不是满足的最大的面积。
#include<bits/stdc++.h>using namespace std;typedef long long ll;int main(){ ll a,b,x,y; while(scanf("%lld%lld%lld%lld",&a,&b,&x,&y) != EOF) { bool flag = false; ll k = __gcd(x,y);//一个小小的坑点 x /= k, y /= k; ll min1 = 0,min2 = 0; if(a < x || b < y) { printf("0 0\n"); continue; } min1 = a/x; min2 = b/y; ll Max = min(min1,min2); a = (Max*x),b = (Max*y); printf("%lld %lld\n",a,b); }}
- 水题:CF16C-Monitor
- monitor
- Monitor
- Monitor
- Monitor
- monitor
- Monitor
- CodeForces 16C Monitor(gcd,水题)
- Monitor.Wait&Monitor.Pulse
- SNMP Monitor
- qRFC-Monitor
- monitor线程
- Monitor MMS
- Monitor Object
- java monitor
- Oracle Monitor
- $monitor(...)//$display(...)
- ubuntu monitor
- 【读书笔记】—— 学习之道、刻意练习
- HDU-1205-吃糖果
- 1.使用Runnable和Thread完成线程创建和基本操作
- 面试题之走楼梯问题
- Echarts可视化开发之树型图(公司人事架构图)
- 水题:CF16C-Monitor
- 亚信实习第三周(7.24-7.30)
- Pycharm Edu 自带入门教程:Getting Started for Educators
- Wolf and Rabbit
- 记使用CRF++做中文命名实体识别
- Android解析ActivityManagerService(一)AMS启动流程和AMS家族
- H5 js 处理localstorage方法封装
- rabbitmq应用场景
- AdaBoost 算法原理及推导