日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【codeforces 807C】Success Rate

發布時間:2025/7/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【codeforces 807C】Success Rate 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

【題目鏈接】:http://codeforces.com/contest/807/problem/C

【題意】

給你4個數字
x y p q
要求讓你求最小的非負整數b;
使得
(x+a)/(y+b)==p/q
同時a為一個整數且0<=a<=b

【題解】

/*(x+a)/(y+b)==p/q;則x+a=npy+b=nq(以上結論只在p和q是互質的情況下有效,當然題目有說p和q互質)a=np-xb=nq-ya<=b因為p<q所以n越大b會越大;又p和q都大于等于0,所以n越大,a和b都是不下降的二分n */


【Number Of WA

3

【完整代碼】

#include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define mp make_pair #define pb push_back #define fi first #define se second #define ms(x,y) memset(x,y,sizeof x)typedef pair<int,int> pii; typedef pair<LL,LL> pll;const int dx[9] = {0,1,-1,0,0,-1,-1,1,1}; const int dy[9] = {0,0,0,-1,1,-1,1,-1,1}; const double pi = acos(-1.0); const int N = 110;int t; LL x,y,p,q;int main() {//freopen("F:\\rush.txt","r",stdin);ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not usecin >> t;while (t--){cin >> x >> y >> p >> q;LL l = 0,r = 1e9,ans = -1;while (l<=r){LL mid = (l+r)>>1;LL a=mid*p-x,b=mid*q-y;if (a>=0 && b>=0 && a<=b){ans = mid;r = mid-1;}elsel = mid+1;}if (ans==-1)cout <<-1<<endl;elsecout <<ans*q-y<<endl;}return 0; }

轉載于:https://www.cnblogs.com/AWCXV/p/7626335.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的【codeforces 807C】Success Rate的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。