E - Euclidean TSP UVALive - 6954 (三分)

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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值