Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline(数学)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline(数学)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目中給出的函數具有周期性,總可以移動到第一個周期內,當然,a<b則無解。
假設移動后在上升的那段,則有a-2*x*n=b,注意限制條件x≥b,n是整數,則n≤(a-b)/(2*b)。滿足條件的x≥(a-b)/(2*n)
假設在下降的那段,2*x-(a-2*x*n)=b,n+1≤(a+b)/(2*b),x≥(a+b)/(2*(n+1))
兩者取最小值
#include<bits/stdc++.h> using namespace std;int main() {int a,b; scanf("%d%d",&a,&b);if(a<b) puts("-1");else {int t1 = a+b, t2 = a-b;int n1 = t1/(2*b)*2, n2 = t2/(2*b)*2;double a1 = t1*1./n1, a2 = t2*1./n2;printf("%.10lf\n",min(a1,a2));}return 0; }?
轉載于:https://www.cnblogs.com/jerryRey/p/4815392.html
總結
以上是生活随笔為你收集整理的Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline(数学)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cmake编译参数
- 下一篇: shell判断输入变量或者参数是否为空