SoundHound Inc. Programming Contest 2018 -Masters Tournament-[C. Ordinary Beauty]
打表找规律的。
- (n = 1) 时, (ans = m)
- (n = 2) 时, (ans = 2*(m-1)*2^{m-2})
- (n = 3) 时,
- (d = 0, ~~ ans = 3*(m-1)*3^{m-2})
- (d = 1, ~~ ans = 4*(m-1)*3^{m-2})
- (d = 2, ~~ ans = 2*(m-1)*3^{m-2})
- (n = 4) 时,
- (d = 0, ~~ ans = 4*(m-1)*4^{m-2})
- (d = 1, ~~ ans = 6*(m-1)*4^{m-2})
- (d = 2, ~~ ans = 4*(m-1)*4^{m-2})
- (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
",ans);
}
else if(d==1){
double ans = 1.0*d1*(m-1.0)/n/n;
printf("%.8f
",ans);
}
else {
double dd = d1 - 1.0*(d-1.0)*2.0;
double ans = 1.0*dd*(m-1.0)/n/n;
printf("%.8f
",ans);
}
return 0;
}