codeforces679 D. Bear and Chase

Posted third2333

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces679 D. Bear and Chase相关的知识,希望对你有一定的参考价值。

codeforces679 D. Bear and Chase
http://blog.csdn.net/Ezereal/article/details/52743686
D Bear and Chase

O(n^3) 暴力
首先 ,枚举第一次放BCD地方
然后枚举罪犯离BCD的距离
然后枚举一下第二次方BCD的地方
再加一点预处理就行了

 

 1 #include<cstdio>
 2 #include<cstring>
 3 using namespace std;
 4 const int N=440;
 5 const double eps=1e-9;
 6 int i,j,k,l,n,m,ch,En,x,y;
 7 int h[N],du[N],a[N][N],b[N][N],nn[N];
 8 double ans,now,p[N],q[N];
 9 struct cc { double p;int x;} A[N];
10 struct edge { int s,n;} E[N*N];
11 void R(int &x) {
12     x=0;ch=getchar();
13     while (ch<0 || 9<ch) ch=getchar();
14     while (0<=ch && ch<=9) x=x*10+ch-0,ch=getchar();
15 }
16 void E_add(int x,int y) {
17     du[x]++;du[y]++;
18     a[x][y]=a[y][x]=1;
19     E[++En].s=y;E[En].n=h[x];h[x]=En;
20     E[++En].s=x;E[En].n=h[y];h[y]=En;
21 }
22 double max(double x,double y) {
23     if (x>y) return x;
24     return y;
25 }
26 double get_num(int x) {
27     int i,j,k,nm=0;
28     for (i=1;i<=n;i++) p[i]=0.0;
29     for (i=1;i<=nn[x];i++)
30         for (k=h[b[x][i]];k;k=E[k].n) p[E[k].s]+=1.0/(1.0*n*du[b[x][i]]);
31     for (i=1;i<=n;i++) if (p[i]>eps) {
32         A[++nm].p=p[i];
33         A[nm].x=i;
34     }
35     double ans=0.0,now;
36     for (i=1;i<=n;i++) {
37         now=0.0;
38         for (j=1;j<=nm;j++) q[a[i][A[j].x]]=0.0;
39         for (j=1;j<=nm;j++) if (A[j].p>q[a[i][A[j].x]]) {
40             now+=A[j].p-q[a[i][A[j].x]];
41             q[a[i][A[j].x]]=A[j].p;
42         }
43         ans=max(ans,now);
44     }
45     return ans;
46 }
47 int main() {
48     memset(a,60,sizeof a);
49     R(n);R(m);
50     for (i=1;i<=n;i++) a[i][i]=0; 
51     for (i=1;i<=m;i++) {
52         R(x);R(y);
53         E_add(x,y);
54     }
55     for (k=1;k<=n;k++)
56         for (i=1;i<=n;i++)
57             for (j=1;j<=n;j++) if (a[i][k]+a[k][j]<a[i][j]) a[i][j]=a[i][k]+a[k][j];
58     for (i=1;i<=n;i++) {
59         now=0.0;
60         for (j=0;j<n;j++) nn[j]=0;
61         for (j=1;j<=n;j++) {
62             k=a[i][j];
63             b[k][++nn[k]]=j;
64         }
65         for (j=0;j<n;j++) if (nn[j]) {
66             if (nn[j]==1) now+=1.0/(1.0*n);
67             else now+=max(1.0/(1.0*n),get_num(j));
68         }
69         ans=max(ans,now);
70     }
71     printf("%.9lf\n",ans);
72 }

 

以上是关于codeforces679 D. Bear and Chase的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 679B - Bear and Tower of Cubes

codeforces679B Bear and Tower of Cubes(思路)

codeforces679A_Bear and Prime 100 交互题

Codeforces679E. Bear and Bad Powers of 42

codeforces679C Bear and Square Grid(dfs优化)

CF679C(Bear and Square Grid) 经典好题