Description
给出 n n 个目标的二维坐标以及炸弹的爆炸位置 (x0,y0) ( x 0 , y 0 ) ,对于一个爆炸半径 R R ,一个距离爆炸位置的目标被摧毁的概率为 P(D)=e1−D2R2,D>R,P(D)=1,D≤R P ( D ) = e 1 − D 2 R 2 , D > R , P ( D ) = 1 , D ≤ R ,先要最小化 R R 使得被摧毁目标的期望数量小于的概率小于 eps1000 e p s 1000
Input
第一行一整数 n n 表示目标个数,之后输入两个整数,然后输入爆炸位置 (x0,y0) ( x 0 , y 0 ) ,最后 n n 行每行输入两个整数表示第 i i 个目标的坐标
Output
输出满足条件的 R R 的最小值,误差不超过
Sample Input
1
1 500
5 5
1 2
Sample Output
3.84257761518762740
Solution
二分 R R ,对于固定的可以求出第 i i 个目标被摧毁的概率,以 dp[i][j] d p [ i ] [ j ] 表示前 i i 个目标有个目标被摧毁的概率,根据第 i i 个目标是否被摧毁有转移, O(n2) O ( n 2 ) 完成转移后,摧毁目标期望数量小于 K K 的概率即为,如果该值大于 eps e p s 说明 R R 过小要尝试更大的,否则说明 R R 合法可以进一步尝试更小的
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
#define x first
#define y second
const int INF=0x3f3f3f3f,maxn=105;
int n,K;
double eps,dp[maxn][maxn];
P s,p[maxn];
double dis(P a,P b)
{
return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+1.0*(a.y-b.y)*(a.y-b.y));
}
bool check(double r)
{
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<=i;j++)
{
double q,d=dis(s,p[i]);
if(d<=r)q=1;
else q=exp(1.0-d*d/(r*r));
if(j==0)dp[i][j]=(1.0-q)*dp[i-1][j];
else dp[i][j]=q*dp[i-1][j-1]+(1.0-q)*dp[i-1][j];
}
double res=0;
for(int i=0;i<K;i++)res+=dp[n][i];
if(res>eps)return 0;
return 1;
}
int main()
{
scanf("%d%d%lf",&n,&K,&eps);
eps/=1000;
scanf("%d%d",&s.x,&s.y);
double l=0,r=0,mid,ans=0;
for(int i=1;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y),r=max(r,dis(s,p[i]));
int T=100;
while(T--)
{
mid=0.5*(l+r);
if(check(mid))ans=mid,r=mid;
else l=mid;
}
printf("%.9f\n",ans);
return 0;
}