传送门:http://codeforces.com/problemset/problem/16/C

Monitor

time limit per test0.5 second

memory limit per test64 megabytes

Problem Description

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.

Input

The first line of the input contains 4 integers — a, b, x and y (1 ≤ a, b, x, y ≤ 2·109).

Output

If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.

Examples input

800 600 4 3

1920 1200 16 9

1 1 1 2

Examples output

800 600

1920 1080

0 0


解题心得:

  1. 题意就是给你一个矩形长为a,宽为b,要你将这个矩形减掉一部分变成长宽比例为x:y,并且要求面积尽可能的大,要求你输出改变后的矩形的长和宽。
  2. 这个题真的很简单,不需要你去将什么长宽调换什么的,就老老实实的按照题意来就可以了。先将x:y变成最简比例,然后a向x缩,b向y缩,两方同时达到要求就停止。用数学方法实现就行了。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int num[maxn];
long long a,b,x,y; int main()
{
while(cin>>a>>b>>x>>y)
{
int t=__gcd(x,y);
x/=t;
y/=t;
t=min(a/x,b/y);//要两个边都同时到达比例才行
long long l1,l2;
l1 = x*t;
l2 = y*t;
printf("%lld %lld\n",l1,l2);
}
return 0;
}

最新文章

  1. git 找回丢失的commit
  2. Android 四种简单的动画(淡入淡出、旋转、移动、缩放效果)
  3. [iOS基础控件 - 6.12.1] QQ菜单管理 UITabBarController 控制器管理
  4. jquery实现asp.net 网页鼠标所在位置
  5. Html笔记(九)头标签
  6. [转贴]一个将表格变成 INSERT 的SQL 语句的存储过程(sql server)
  7. sphinx随笔记了一下
  8. keepalived实现服务高可用
  9. 第三方工具 - 关于echarts下钻功能的一些总结.js
  10. Android Multimedia框架总结(十一)CodeC部分之AwesomePlayer到OMX服务
  11. java并发包分析之———Deque和LinkedBlockingDeque
  12. python 解方程 和 python 距离公式实现
  13. 使用Promise解决多层异步调用的简单学习【转】
  14. 理解REST和RPC
  15. recovery 差分升级包制作超时
  16. java.——最大子序列和(前提是:全部都是非负数)
  17. 牛客第二场A-run
  18. 2.16 C++类与new和delete操作符
  19. 火狐浏览器flash经常奔溃的
  20. 【Tomcat】Tomcat容器 web.xml详解

热门文章

  1. 使用Zeppelin时出现at org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService$Client.recv_getFormType(RemoteInterpreterService.java:288)错误的解决办法(图文详解)
  2. (译)Minimal Shader(最小的着色器)
  3. intelliJ idea 激活和配置
  4. vue-quill-editor上传内容由于图片是base64的导致字符太长的问题解决
  5. mysql操作封装
  6. 零基础逆向工程11_C语言05_结构体
  7. java 通过文件后缀名查找文件
  8. 一个mybatis错误导致无法启动项目的问题
  9. 有一个无效 SelectedValue,因为它不在项目列表中
  10. ReferenceError: internalBinding is not defined