SoundHound Inc. Programming Contest 2018[C. Ordinary Beauty]

SoundHound Inc. Programming Contest 2018 -Masters Tournament-[C. Ordinary Beauty]


打表找规律的。

  1. \(n = 1\) 时, \(ans = m\)
  2. \(n = 2\) 时, \(ans = 2*(m-1)*2^{m-2}\)
  3. \(n = 3\) 时,
    1) \(d = 0, ~~ ans = 3*(m-1)*3^{m-2}\)
    2) \(d = 1, ~~ ans = 4*(m-1)*3^{m-2}\)
    3) \(d = 2, ~~ ans = 2*(m-1)*3^{m-2}\)

  4. \(n = 4\) 时,
    1) \(d = 0, ~~ ans = 4*(m-1)*4^{m-2}\)
    2) \(d = 1, ~~ ans = 6*(m-1)*4^{m-2}\)
    3) \(d = 2, ~~ ans = 4*(m-1)*4^{m-2}\)
    4) \(d = 3, ~~ ans = 2*(m-1)*4^{m-2}\)
    发现:

    2 2
    3 4 2
    4 6 4 2
    5 8 6 4 2
    6 10 8 6 4 2

上图规律就显然了。

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,m,d;
int main() {
    scanf("%lld%lld%lld",&n,&m,&d);
    double d0 = n, d1 = (n-1.0)*2.0;
    if(d==0){
        double ans = 1.0*d0*(m-1.0)/n/n;
        printf("%.8f\n",ans);
    }
    else if(d==1){
        double ans = 1.0*d1*(m-1.0)/n/n;
        printf("%.8f\n",ans);
    }
    else {
        double dd = d1 - 1.0*(d-1.0)*2.0;
        double ans = 1.0*dd*(m-1.0)/n/n;
        printf("%.8f\n",ans);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/RRRR-wys/p/9278660.html