codeforces 578a//A Problem about Polyline// Codeforces Round #320 (Div. 1)
题意:一个等腰直角三角形一样的周期函数(只有x+轴),经过给定的点(a,b),并且半周期为X,使X尽量大,问X最大为多少?
如果a=b,结果就为b
如果a<b无解。
否则,b/(2*k*x-a)=1或者b/(a-2*k*x)=1;以前者为例,x=(a-b)/(2*k)。x越小越好,那么k尽量大,但是K过大,x就会小于b,x小于b就无法穿过(a,b)。k要大又不能过大就满足二分的要求,就能二分。
乱码:
//#pragma comment(linker,"/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> #include <stack> #include <iomanip> using namespace std; const int SZ=1000010,INF=0x7FFFFFFF; const double EPS=1e-8; double getr(double res,int b) { if(res<b)return 1e300; int lo=2,hi=1e9+10; for(;lo<hi;) { int mid=(lo+hi)/2; if(res/mid>=b||fabs(res/mid-b)<EPS*EPS)lo=mid+1; else hi=mid; } //cout<<res<<" "<<lo<<endl; return res/(lo-1); } double work(double a,double b) { if(fabs(a-b)<EPS)return b; else { double na=a,nb=b; double res1=(na-nb)/2,res2=(na+nb)/2; // res1=getr(res1,b); res2=getr(res2,b); //cout<<res1<<" "<<res2<<endl; return min(res1,res2); } } int main() { //std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); //for(;scanf("%d",&n)!=EOF;) { double a,b; cin>>a>>b; if(a<b)cout<<-1<<endl; else { cout<<fixed<<setprecision(10)<<work(a,b)<<endl; } } return 0; }
浙公网安备 33010602011771号