zoukankan      html  css  js  c++  java
  • 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
    ",ans);
    72 }
  • 相关阅读:
    CSS选择器
    基础DOS命令
    超链接a标签
    vscode使用技巧
    pc端页面添加meta标签:X-UA-Compatible meta标签
    提问的智慧
    Zepto核心模块源代码分析
    远程调试工具weinre使用教程
    HTML标签marquee实现滚动效果
    git 学习教程
  • 原文地址:https://www.cnblogs.com/third2333/p/7637005.html
Copyright © 2011-2022 走看看