您的位置:首页 > 其它

E - Euclidean TSP UVALive - 6954 (三分)

2017-02-23 21:37 330 查看
Uva https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4966
Vjudge https://vjudge.net/problem/UVALive-6954
看不t 23333333333

上下界0 - 100 大神说随缘。。。

码着三分吧

注意精度 esp 其实最后输出7位就可以了

#include <algorithm>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <map>

using namespace std;

#define sf scanf
#define pf printf
#define ll long long
#define For(i,a,b) for(i=a;i<=b;i++)
#define _For(i,a,b) for(i=b;i>=a;i--)
#define Out(x) cout<<x<<endl
#define Outdouble(x,a) cout<<fixed<<setprecision(a)<<1.0*x<<endl
#define _Outdouble(x,a) cout<<fixed<<setprecision(a)<<1.0*x
#define mset(arr,num) memset(arr,num,sizeof(arr))
#define ok std::ios::sync_with_stdio(0)
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize("O3")

const ll inf = 1e12+10;  ///
const double esp = 1e-7; ///
const int NUM = 1e5+10;

// #define debug
#if defined (debug)
---check---
#endif

/// ^_^  ^_^  ^_^  ^_^  ^_^  ^_^  ^_^  ^_^  ^_^  ^_^  ^_^  ^_^  ^_^ ///

///三分用来求单峰函数的极(最)值
///二分是求单调函数的最值

double two = sqrt(2);
double p,s,v;
int n;

double cal(double x)
{
return s*(1+1/x)/v + n*pow(log2(n),x*two)/p/1e9;
}

int main()
{
double l,r;
double mid,midmid;
while(cin>>n>>p>>s>>v)
{
l = 0,r = 100; ///
while(r - l > esp)
{
mid = (l+r)/2.0;
midmid = (mid + r)/2.0;
if(cal(mid) < cal(midmid))  ///求极小值 极大值下面边界相反
{
r = midmid;
}
else
{
l = mid;
}
}
_Outdouble(cal(l),14);
cout<<" ";
Outdouble(l,14);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息