【数学】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 让你求第一个分数变化到第二个分数的最小步数. 思路 有几种特殊情况分类讨论一下. 首先我 ...
随机推荐
- nodejs的mysql模块学习笔记(结合业务)
1. 包官网地址 https://www.npmjs.com/package/mysql#install https://www.oschina.net/translate/node-mysql-tu ...
- Ajax深入理解
Ajax Asynchronous JavaScript and XML 异步的JavaScript和XML ajax通过与后台服务器进行少量的数据交换,ajax可以使页面实现异步更新,即不需要重新 ...
- EEPROM介绍
EEPROM( Electrically Erasable Programmable Read Only Memory )全称是电气可擦除可编程只读存储器,是非易失存储器,可以访问到每个字节,容量比较 ...
- jQuery ajax参数后台获取不到的问题
<script type="text/javascript"> init(); var alldate = {a : "0",b:"1&q ...
- Mysql无法启动服务解决办法
只需要输入:mysqld --initialize 进行初始化,即可启动
- centos7环境搭建Eureka-Server注册中心集群
目的:测试和线上使用这套独立的Eureka-Server注册中心集群,目前3台虚拟机集群,后续可直接修改配置文件进行新增或减少集群机器. 系统环境: Centos7x64 java8+(JDK1.8+ ...
- C# 递归读取XML菜单数据
在博客园注册了有4年了,很遗憾至今仍未发表过博客,趁周末有空发表第一篇博客.小生不才,在此献丑了! 最近在研究一些关于C#的一些技术,纵观之前的开发项目的经验,做系统时显示系统菜单的功能总是喜欢把数据 ...
- (转)Spring4.2.5+Hibernate4.3.11+Struts2.3.24整合开发
http://blog.csdn.net/yerenyuan_pku/article/details/52902851 前面我们已经学会了Spring4.2.5+Hibernate4.3.11+Str ...
- python 网络编程篇
基础模拟通话网络程序: #客户端 import socket client = socket.socket() client.connect(('localhost',6969)) client.se ...
- adb 调试真机 wait for device 错误解决办法
起因 真机测试,使用adb安装和卸载应用时,出现wait for device. 解决办法 拔掉USB重新插入即可.