题目链接:http://codeforces.com/problemset/problem/807/C

题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再提交几次可以达到目标正确率p/q;

解题思路:假设提交B次,正确A次,那么可以得到(x+A)/(y+B)=p/q,可以推出x+A=k*p,y+B=k*q.那么A=k*p-x,B=K*q-y;

这样我们只需要二分枚举k,判断A,B是否满足(0<=A<=B)即可。

 #include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL; int main(){
int T;
cin>>T;
while(T--){
LL x,y,p,q;
cin>>x>>y>>p>>q;
LL l=,r=1e10,mid;
LL ans=<<;
while(l<=r){
mid=(l+r)/;
LL A=mid*p-x;
LL B=mid*q-y;
if(A>=&&B>=&&A<=B){//判断是否满足(0<=A<=B)
ans=min(ans,mid);
r=mid-;
}
else
l=mid+;
}
if(ans!=<<)
cout<<ans*q-y<<endl;
else
cout<<"-1"<<endl;
}
return ;
}

Codeforces 807C - Success Rate(二分枚举)的更多相关文章

  1. Codeforces - 773A - Success Rate - 二分 - 简单数论

    https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...

  2. Success Rate CodeForces - 807C (数学+二分)

    You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...

  3. CodeForce-807C Success Rate(二分数学)

    Success Rate CodeForces - 807C 给你4个数字 x y p q ,要求让你求最小的非负整数b,使得 (x+a)/(y+b)==p/q,同时a为一个整数且0<=a< ...

  4. Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))

    题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...

  5. 【数学】codeforces A. Success Rate

    http://codeforces.com/contest/773/problem/A [思路] 用 (x+a)/(y+b) = p/q 来表示其核心思想,其中a 为做对的题目,b为做的题目,则有x+ ...

  6. AC日记——Success Rate codeforces 807c

    Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  7. Codeforces Round #412 C. Success Rate

    C. Success Rate time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. Codeforces 807 C. Success Rate

    http://codeforces.com/problemset/problem/807/C C. Success Rate time limit per test 2 seconds memory ...

  9. Codeforces 651D Image Preview【二分+枚举】

    题意: 若干张照片,从头开始可以向左右两边读,已经读过的不需要再读,有的照片需要翻转,给定读.滑动和翻转消耗的时间,求在给定时间内最多能读多少页? 分析: 首先明确,只横跨一次,即先一直读一边然后再一 ...

随机推荐

  1. 加ico

    <link rel="icon" type="text/css" href="/favicon.png" />

  2. python基础之while语句continue以及break --语法以及案例

    1.while 死循环 [root@localhost python]# cat while.py #!/usr/bin/env python # _*_ coding:utf8 _*_ import ...

  3. 理解jquery的$.extend()、$.fn和$.fn.extend()的区别及用法

    viajQuery为开发插件提拱了两个方法,分别是: jQuery.fn.extend(); jQuery.extend(); jQuery.fn jQuery.fn = jQuery.prototy ...

  4. python 启航

    first = 1while first<=9: sec = 1        while sec <= first:        print(  str(sec)+"*&qu ...

  5. 转:UINavigationBar返回上一级出现nested pop animation can result in corrupted navigation bar

    [self.navigationController popViewControllerAnimated:NO]; 出现上面的错误是因为pop的时候要确保先让本页面加载完成,即如果在viewDidLo ...

  6. 2017 国庆湖南 Day1

    卡特兰数 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ] ...

  7. python学习笔记4--函数/全局变量/递归

    一.函数是什么? 函数一词来源于数学,但编程中的「函数」概念,与数学中的函数是有很大不同的,编程中的函数在英文中也有很多不同的叫法.在BASIC中叫做subroutine(子过程或子程序),在Pasc ...

  8. [转载]asp.net mvc: why is Html.CheckBox generating an additional hidden input

    http://stackoverflow.com/questions/2697299/asp-net-mvc-why-is-html-checkbox-generating-an-additional ...

  9. 推荐一些我所用的firefox 附加组件。

    firefox之所以强大,很大程度上是因为它有着超多的扩展组件,来实现许多有趣的功能.这几天把我装的firefox附加组件整理下,个人认为是一般上网常用或者可以说是必备的组件,o(∩_∩)o ,晒晒. ...

  10. 20155117王震宇实验四 Andoid开发基础实验报告

    实验内容 1.Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)>第二十四章: - ...