結果
| 問題 |
No.1936 Rational Approximation
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2022-05-13 22:22:01 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,379 ms / 2,000 ms |
| コード長 | 771 bytes |
| コンパイル時間 | 6,477 ms |
| コンパイル使用メモリ | 256,068 KB |
| 最終ジャッジ日時 | 2025-01-29 07:09:58 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
//参考元
//https://tjkendev.github.io/procon-library/python/math/stern-brocot-tree.html
vector<ll> Stern_Brocot(ll p, ll q, ll n){
ll a=0,b=1,c=1,d=0;
bool lu=true,ru=true;
ll lx=0,ly=1,rx=1,ry=0;
ll times=1000000010;
ll s,t;
while (times){
times--;
s=a+c; t=b+d;
if (t*p<s*q){
c=s; d=t;
if (t<=n){
rx=s; ry=t;
}else{
ru=false;
}
}
if (t*p>s*q){
a=s; b=t;
if (t<=n){
lx=s; ly=t;
}else{
ru=false;
}
}
}
return vector<ll>{lx,ly,rx,ry};
}
int main(){
ll P,Q;
cin >> P >> Q;
vector<ll> v=Stern_Brocot(P,Q,Q);
cout << v[0]+v[1]+v[2]+v[3] << endl;
}
Kazun