[Codeforces Round #195 DIV2B (CF336B)] Vasily the Bear and Fly
2017-01-30 19:00
639 查看
题意
题面比较复杂2m个圆排成两排,每排m个圆。标号以排连续
天数从0到m2−1,第i天时,苍蝇从v=⌊im⌋+1出发,到u=m+1+(imodm)去,在路径在圆内部前提下沿着最短路飞行。求飞行距离的平均长度。
样例
2 2
题解
分析一下起点和终点会发现起点在第一排,终点在第二排所有情况都会出现一次,那么计算就好计算了。然而这题还是有trick的,并不是所有的最短路径都跟样例似的只有一个R−−√,会有如图所示情形。
代码
/// by ztx /// blog.csdn.net/hzoi_ztx #define Rep(i,l,r) for(i=(l);i<=(r);i++) #define rep(i,l,r) for(i=(l);i< (r);i++) #define Rev(i,r,l) for(i=(r);i>=(l);i--) #define rev(i,r,l) for(i=(r);i> (l);i--) #define r(x) read(x) typedef long long ll ; typedef double lf ; int CH , NEG ; template <typename TP>inline void read(TP& ret) { ret = NEG = 0 ; while (CH=getchar() , CH<'!') ; if (CH == '-') NEG = true , CH = getchar() ; while (ret = ret*10+CH-'0' , CH=getchar() , CH>'!') ; if (NEG) ret = -ret ; } int m, R, v; lf ans; const lf sqrt2 = sqrt(2); inline lf s(int n) { return n * (2.0 * (sqrt2 + 1) + 1.0 * (n - 1)); } int main() { r(m), r(R); ans = .0; Rep (v,1,m) { ans += 2; if (v > 1) ans += 2+sqrt2+s(v-2); if (v < m) ans += 2+sqrt2+s(m-v-1); } printf("%.10lf\n", ans * R / m / m); END: getchar(), getchar(); return 0; }
相关文章推荐
- Codeforces Round #195 (Div. 2) B. Vasily the Bear and Fly - 找规律
- CF#195(div2) B:Vasily the Bear and Fly
- cf B. Vasily the Bear and Fly
- [Codeforces Round #195 DIV2D (CF336D)] Vasily the Bear and Beautiful Strings
- [Codeforces Round #195 DIV2E (CF336E)] Vasily the Bear and Painting Square
- Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle
- A. Vasily the Bear and Triangle
- Codeforces 336A【 Vasily the Bear and Triangle 】
- cf A. Vasily the Bear and Triangle
- CodeForces #195 Div.2-A. Vasily the Bear and Triangle
- Codeforces Round #195 (Div. 2) A Vasily the Bear and Triangle
- [Codeforces Round #195 (Div. 2)] A. Vasily the Bear and Triangle
- CF#195(div2) A:Vasily the Bear and Triangle
- Codeforces Round #195 (Div. 2) C--Vasily the Bear and Sequence(贪心)
- Codeforces Round #195 (Div. 2) D题Vasily the Bear and Beautiful Strings
- Codeforces-336A-Vasily the Bear and Triangle
- Create Snazzy Web Charts and Graphics On the Fly with the .NET Framework
- on-the-fly and pre-computed?
- git pull报错:Auto Merge Failed; Fix Conflicts and Then Commit the Result.
- HDU 1026 Ignatius and the Princess I (BFS+记录路径)