标签:
题目中给出的函数具有周期性,总可以移动到第一个周期内,当然,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; }
Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline
标签:
原文地址:http://www.cnblogs.com/jerryRey/p/4815392.html