AC日记——Success Rate codeforces 807c
思路:
水题;
代码:
#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的更多相关文章
- Success Rate CodeForces - 807C (数学+二分)
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...
- AC日记——Cards Sorting codeforces 830B
Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Card Game codeforces 808f
F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...
- AC日记——T-Shirt Hunt codeforces 807b
T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...
- AC日记——Magazine Ad codeforces 803d
803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <io ...
- AC日记——Broken BST codeforces 797d
D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...
- AC日记——Array Queries codeforces 797e
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
- AC日记——Vicious Keyboard codeforces 801a
801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...
随机推荐
- 【SSH】——封装参数不确定的分页查询
[前言] 在BS中,分页技术的应用相当频繁.说到分页,简单的分页就很好实现了,如果在分页的基础上再加上业务逻辑,这就使得分页的技术更加的灵活了. [简单分页] 我们先看一种简单的分页,为了做到复用,我 ...
- 购物车实现思路:cookie + 数据库
一.加入购物车 1.用户未登录 ==> 将商品id和商品数量存为数组 ==>序列化后存到cookie中 代码: if(!isset($_SESSION['uid'])){ if(empt ...
- SQL Server “超过了锁请求超时时段”错误
错误提示:“已超过了锁请求超时时段. (Microsoft SQL Server,错误: 1222)”(英文:“Lock Request time out period exceeded.(Micro ...
- springMVC笔记一
第一章 回顾JavaWeb中的MVC设计模式 1)MVC这种设计模式,不光运用于Web领域,而且也能用于非Web领域 2)今天说的MVC特指一种表现层设计模式,不限于Java语言 第二章 回顾stru ...
- Powershell使用真实的对象工作
Powershell使用真实的对象工作 来源 https://www.pstips.net/powershell-work-with-reallife-objects.html 每一个Powershe ...
- [bzoj1018] [SHOI2008]堵塞的交通
题目描述 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常奇特,整个国家的交通系统可以被看成是一个22行CC列的矩形网格,网格上的每个点代表一个城市,相邻的城市之间有一条道路,所 ...
- 打造适合日常使用的ubuntu,以ubuntu 16.04.1 LTS为例(不涉及版本)
因为调试些程序需要用到ubuntu,又不喜欢虚拟机,因此装了双系统,在这过程中因为各种原因ubuntu来回安装过好多次,每次安装到用得爽都要捣鼓很久,也算稍微有点经验心得,将ubuntu调教的过程写在 ...
- Install the AWS Command Line Interface on Linux
Install the AWS Command Line Interface on Linux You can install the AWS Command Line Interface and i ...
- jsp分页完善版
明天要考网络工程师了,而且这两天校运会,把那个分页的完善了下,明天考试,祈祷吧,我根本都没看书啊,所以只能去长见识了.100大洋啊,下个学期我想考考证了,不然以后出去麻烦了.呵呵,不多说还是说说自己对 ...
- php windows rename 中文出错
php windows rename 中文出错 rename()函数可以重命名文件.目录等,但是要注意目的地和起始地址的编码. 比如:我的PHP文件编码是UTF-8,但是在WINDOW系统中中文默认编 ...