【数学】codeforces A. Success Rate
http://codeforces.com/contest/773/problem/A
【思路】
用 (x+a)/(y+b) = p/q 来表示其核心思想,其中a 为做对的题目,b为做的题目,则有x+a = k*p,y+b = k*q.且有0<=a<=b,两式合并可得k>=x/p,k>=(y-x)/(q-p), 则如要满足两个等式,k应取其中较大的值(注意:若取得的k为小数,我们需要的是最小整数解,加1),最后注意一下特殊情况 p = 0,p = q.
最后要注意long long,max(m,n)*q会爆long long。
【Accepted】
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll; int main()
{
int T;
int x,y,p,q;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&x,&y,&p,&q);
if(p==q)
{
if(x==y)
{
printf("0\n");
}
else
{
printf("-1\n");
}
continue;
}
if(p==)
{
if(x==)
{
printf("0\n");
}
else
{
printf("-1\n");
}
continue;
}
int m=(y-x)/(q-p)+((y-x)%(q-p)?:);
int n=x/p+(x%p?:);
cout<<(ll)max(m,n)*(ll)q-(ll)y<<endl;
}
return ;
}
【数学】codeforces A. Success Rate的更多相关文章
- Codeforces 807C - Success Rate(二分枚举)
题目链接:http://codeforces.com/problemset/problem/807/C 题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再 ...
- Codeforces - 773A - Success Rate - 二分 - 简单数论
https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...
- Success Rate CodeForces - 807C (数学+二分)
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...
- Codeforces Round #412 C. Success Rate
C. Success Rate time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 807 C. Success Rate
http://codeforces.com/problemset/problem/807/C C. Success Rate time limit per test 2 seconds memory ...
- CodeForce-807C Success Rate(二分数学)
Success Rate CodeForces - 807C 给你4个数字 x y p q ,要求让你求最小的非负整数b,使得 (x+a)/(y+b)==p/q,同时a为一个整数且0<=a< ...
- AC日记——Success Rate codeforces 807c
Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- Codeforces807 C. Success Rate 2017-05-08 23:27 91人阅读 评论(0) 收藏
C. Success Rate time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- C. Success Rate
Success Rate 题目链接 题意 给你两个分数形式的数,然后有两种变化方式 上下都+1 仅下面部分+1 让你求第一个分数变化到第二个分数的最小步数. 思路 有几种特殊情况分类讨论一下. 首先我 ...
随机推荐
- Unity3d中UnityEngine.Object
UnityEngine.Object继承自system.Object,是Unity所涉及所有物体的基类. Static Functions 静态函数 下面的都是静态函数 Destroy Remov ...
- Ionic之页面传值
很多时候,我们都进入一个页面往往都是需要将上一级的数据转入到下一级页面中使用,在传传统的html中时经过url来传值,所以ionic也是沿用了html中的方法. 但是还是有点区别于html.我们直接在 ...
- 如何配置TomCat
1.先查看你自己java的jdk的版本号 2.通过jdk版本号确定下载的Tomcat版本 ,因为我的是jdk 1.8的,所以要下载Tomcat 8版本 附上下载官网http://tomcat.apac ...
- check_http.c:312: error: ‘ssl_version’
安装nagios-plugins-1.4.16,安装的过程中出现了错误,提示如下.check_http.c:312: error: ‘ssl_version’ undeclared (first us ...
- 一个简单的139邮箱登录脚本--->java-selenium
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebE ...
- Unity查找物体的四大主流方法及区别
GameObject.Find()优点: 使用简单方便不会因为重名而报错,同时查找的是自上而下的第一个物体缺点 不能查找被隐藏的物体,否则出现“空引用异常”,这是很多新人在查找出现空引用bug的原因. ...
- php bz2扩展安装
php bz2扩展安装 2017年09月22日 14:14:36 Cookie_1030 阅读数:1781 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...
- unnamed not found for the web module
intellij idea tomcat 启动报错not found for the web module 使用intellij idea 创建tomcat项目的时候会出现该错误: 启动tomcat的 ...
- zabbix4.2学习笔记系列
写在前面:对zabbix的接触始于对监控的了解,网上比较多zabbix相关博客,比较多基于3系列甚至2系列,最新开发版zabbix4.2版本已经出来,本博客基于4.2版本学习,参考官网4.2版本和网上 ...
- svn 设置代理
Memory4Young Do Not Repeat Yourself! SVN —— 如何设置代理 如果在使用SVN下载外网的资源时,出现这样的提示:No such host is known. 或 ...