Success Rate

思路:

  水题;

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define ll long long inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
} int main()
{
ll t,x,y,p,q;
in(t);
for(;t--;)
{
in(x),in(y),in(p),in(q);
p/=gcd(p,q),q/=gcd(p,q);
if(q==p)
{
if(x!=y)
{
printf("-1\n");
continue;
}
}
if(p==)
{
if(x!=)
{
printf("-1\n");
continue;
}
}
ll pos=(q-y%q)%q;
double ki=(double)p/(double)q,li,ri;
ll l=,r=,ans;
while(l<=r)
{
int mid=l+r>>;
li=(double)x/(double)(y+pos+(mid*q));
ri=(double)(x+pos+mid*q)/(double)(y+pos+mid*q);
if(ki>=li&&ki<=ri) ans=mid,r=mid-;
else l=mid+;
}
printf("%lld\n",pos+ans*q);
// cout<<pos+ans*q;
// putchar('\n');
}
return ;
}

AC日记——Success Rate codeforces 807c的更多相关文章

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

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

  2. AC日记——Cards Sorting codeforces 830B

    Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  3. AC日记——Card Game codeforces 808f

    F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...

  4. AC日记——T-Shirt Hunt codeforces 807b

    T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  5. AC日记——Magazine Ad codeforces 803d

    803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <io ...

  6. AC日记——Broken BST codeforces 797d

    D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...

  7. AC日记——Array Queries codeforces 797e

    797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...

  8. AC日记——Maximal GCD codeforces 803c

    803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...

  9. AC日记——Vicious Keyboard codeforces 801a

    801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. 【Android入门】——模拟器的创建及常见问题汇总

    [前言] 刚刚接触Android,第一门课我们就来创建一个模拟器.安卓模拟器,简称AVD(Android Virtual Device),是安卓运行的虚拟设备.有了他以后,我们就不需要在连着安卓手机进 ...

  2. 【转】深入理解Java中的String

    原文链接:http://www.cnblogs.com/xiaoxi/p/6036701.html 一.String类 想要了解一个类,最好的办法就是看这个类的实现源代码,来看一下String类的源码 ...

  3. BZOJ4476 送礼物

    这道题真是有趣呀. 其实就是一个分数规划问题,用一个二分加log来得去掉分母. 分四种情况讨论 1.lenth > L && num ( max ) > num ( min ...

  4. FAQ: SNMP on NetScaler Appliance

    FAQ: SNMP on NetScaler Appliance https://support.citrix.com/article/CTX122436 https://docs.citrix.co ...

  5. 【题解】SDOI2016征途

    就放个代码吧……实在是太套路了.不过据说有复杂度还要低很多的算法,不知道是怎么做呀…… #include <bits/stdc++.h> using namespace std; #def ...

  6. [BZOJ3473][BZOJ3277]字符串

    [BZOJ3473][BZOJ3277]字符串 试题描述 给定 \(n\) 个字符串,询问每个字符串有多少子串(不包括空串)是所有 \(n\) 个字符串中至少 \(k\) 个字符串的子串? 输入 第一 ...

  7. 安装全局webpack

    npm ls webpack 和npm ls webpack -g 查看本地和全局版本 npm install webpack@1.15.0 -g 全局 然后到项目里面 npm install npm ...

  8. [Leetcode] Binary tree maximum path sum求二叉树最大路径和

    Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...

  9. 线程 packaged_task future

    http://www.cnblogs.com/haippy/p/3279565.html #include <iostream> // std::cout #include <fut ...

  10. DOM 2

    1.对文档的信息进行检索常用的方法: getElementById; getElementsByTagName; getAttribute;//得到的是属性值 2把需要的信息添加到DOM中常用的方法: ...