Pacifist

2 篇文章 0 订阅

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
我一开始的思路是:
期望=总和/个数,所以枚举每种可能的竞赛图,Tarjan 求
出强连通分量O(n^2 2^n(n-1)/2),时间复杂度超标

正确的是
设 a[i]表示 i 个点的强连通的竞赛图个数。枚举缩点+拓扑排序后最后一个新点包含的点数,可列出式子:
在这里插入图片描述
将 a[n]移至左边,得到 a[n]递推式为:

在这里插入图片描述

显然每个点是等价的。设每个点的点权为所在强连通分量大小对应的 d,则所有图权值的和等于所有图所有点点权的和/n。设 f[n]表示所有 n 个点的竞赛图所有点点权的和,枚举缩点+拓扑排序后最后一个新点包含的点数。

#include<bits/stdc++.h>
using namespace std;
typedef double DB;
const DB eps=1e-10,pi=acosl(-1.0);
const int maxn=1505;
int W,H,n;
DB D[maxn][maxn],lim;
struct point
{
 DB x,y;
 point(){}
 point(const DB &_x,const DB &_y):x(_x),y(_y){}
 point operator+(const point &o)const{return point(x+o.x,y+o.y);}
 point operator-(const point &o)const{return point(x-o.x,y-o.y);}
 bool operator==(const point &o)const{return fabs(x-o.x)+fabs(y-o.y)<eps;}
 DB ang(){return atan2(y,x);}
}P[maxn];
DB dist(const point &p)
{
 return sqrt(p.x*p.x+p.y*p.y);
}
pair<DB,int> e[maxn*2];
int en,cnt;
void add(DB l,DB r,int c=1)
{
 if(l<-pi)
  cnt+=c,l+=pi*2;
 if(r>pi)
  cnt+=c,r-=pi*2;
 e[++en]=make_pair(l,c),
 e[++en]=make_pair(r,-c);
}
bool check(int k,DB r)
{
 en=cnt=0;
 point p=P[k];
 DB a,t,d;
 if(r>(d=p.x))
 {
  a=-pi;
  t=acos(d/r);
  add(a-t,a+t,2);
 }
 if(r>(d=p.y))
 {
  a=-pi/2;
  t=acos(d/r);
  add(a-t,a+t,2);
 }
 if(r>(d=W-p.x))
 {
  a=0;
  t=acos(d/r);
  add(a-t,a+t,2);
 }
 if(r>(d=H-p.y))
 {
  a=pi/2;
  t=acos(d/r);
  add(a-t,a+t,2);
 }
 for(int i=1;i<=n;i++)
 {
  if(i!=k&&!(P[i]==P[k]))
  {
   p=P[i]-P[k];
   d=D[i][k];
   if(r+r>d)
   {
    a=p.ang();
    t=acos(d/r/2);
    add(a-t,a+t);
   }
  }
 }
 sort(e+1,e+en+1);
 if(cnt<=1)
  return 1;
 for(int i=1;i<=en;i++)
 {
  if(cnt<=1)
   return 1;
  else 
   cnt+=e[i].second;
 }
 return 0;
}
void init()
{
 scanf("%d%d%d",&W,&H,&n);
 for(int i=1;i<=n;i++)
  scanf("%lf%lf",&P[i].x,&P[i].y);
 random_shuffle(P+1,P+n+1);
 for(int i=1;i<=n;i++)
  for(int j=1;j<=n;j++)
   D[i][j]=dist(P[i]-P[j]);
 lim=dist(point(W,H));
}
void work()
{
 DB ans=0,low,high,mid;
 for(int i=1;i<=n;i++)
  if(check(i,ans+eps))
  {
   low=ans,high=lim;
   for(int t=60;t--;)
   {
    mid=(low+high)/2;
    if(check(i,mid))low=mid;
    else high=mid;
   }
   ans=low;
  }
 printf("%.12lf\n",double(ans));
}
int main()
{
 init();
 work();
 return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值