A - Euclidean TSP UVALive - 6954(三分)

problem

The famous Arora-Mitchell approximation algorithm for the
Euclidean Travelling Salesman Problem (Euclidean TSP) was
discovered independently by Sanjeev Arora and Joseph S. B.
Mitchell in 1998. It can approximate the value of an optimal
TSP tour in d dimensions within a factor of 1 + 1
c
in running
time
n(log n)
O((c

d)
d−1
)
,
where n is the number of nodes in the tour.
Miroslava works for a computer security company and it is time to renew a shared cryptographic
key in many data centres across Europe. To do this, Miroslava is going to rent a private jet and deliver
the key to employees waiting at all major European airports. She wants to be back as soon as possible.
Miroslava’s company has a computer that is able to execute p billions of operations per second.
Since we can approximate Europe by a two-dimensional plane, we assume that the Arora-Mitchell
algorithm runs for exactly
n(log2 n)
c

2
p · 109
seconds on this computer to produce the exact (1 + 1/c)-approximation of the optimal tour.
Miroslava noticed that c is a parameter of the algorithm that can be used to her advantage, but
one also needs to be very careful when choosing the right value. If she sets c too low, the algorithm
will finish very fast but the time she spends flying around Europe will be too long. On the other hand,
setting it too high will force her to wait for an answer from the computer, while she could be flying
instead.
Miroslava used to work in a different company and from there she knows that the optimal tour
of all major European airports is s meters long, but she wasn’t ranked high enough in the company
to know the actual tour. Given the speed v of the private jet in meters per second, Miroslava needs
s(1 + 1/c)/v seconds to complete the tour produced by the algorithm run with parameter c. For the
sake of simplicity, we assume that Miroslava can land, leave a copy of the private key and take off from
each airport in an instant.
How long does it take Miroslava to first run the algorithm and then distribute all the keys, assuming
that she chooses the optimal parameter c?

原题链接
UVALive - 6954
https://vjudge.net/problem/UVALive-6954

思路

三分
c上线全靠猜
guess100 1A

代码示例

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int debug_num=0;
#define debug cout<<"debug "<<++debug_num<<" :"

const double eps=1e-7;

double n,p,s,v;

double log2(double x)
{
    return log(x)/log(2);
}

const double sqrt2=sqrt(2);

double fun(double c)
{
    //cout<<s<<" "<<c<<" "<<v<<endl;
    double t1=s*(1+1/c)/v;
    double t2=n*pow(log2(n),c*sqrt2)/p/1e9;
    //cout<<t1<<" "<<t2<<endl;
    return t1+t2;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //ios::sync_with_stdio(false);
    while(cin>>n>>p>>s>>v){
    double l=0,r=1e2;
    while(r-l>eps)
    {
        //debug<<l<<" "<<r<<endl;
        double mid=(l+r)/2;
        double midmid=(mid+r)/2;
        double mid_v=fun(mid);
        double midmid_v=fun(midmid);
        if(mid_v>=midmid_v) l=mid;
        else r=midmid;
    }
    printf("%.6lf %.6lf\n",fun(r),r);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值