Circle(山东省第五届ACM大学生程序设计竞赛 )
2017-05-21 18:31
429 查看
Problem Description
You have been given a circle from 0 to n - 1. If you are currently at x, you will move to (x - 1) mod n or (x + 1) mod n with equal probability. Now we want to know the expected number of steps you need to reach x from 0.Input
The first line contains one integer T — the number of test cases.Each of the next T lines contains two integers n, x (0 ≤ x < n ≤ 1000) as we mention above.
Output
For each test case. Print a single float number — the expected number of steps you need to reach x from 0. The figure is accurate to 4 decimal places.Example Input
3 3 2 5 4 10 5
Example Output
2.0000 4.0000 25.0000
完全水过;
好久没写过这么短的代码了。。。。
#include<iostream> #include<cstdio> using namespace std; int t; double a,b; int main() { scanf("%d",&t); while(t--) { scanf("%lf%lf",&a,&b); printf("%.4lf\n",(a-b)*b); } return 0; }
相关文章推荐
- 2014年山东省第五届ACM大学生程序设计竞赛-B-Circle
- 山东省第五届ACM大学生程序设计竞赛 Colorful Cupcakes
- SDUT 2879 Colorful Cupcakes (2014年山东省第五届ACM大学生程序设计竞赛)
- 山东省第五届ACM大学生程序设计竞赛 angry_birds_again_and_again 求积分
- 山东省第五届ACM大学生程序设计竞赛-Weighted Median(模拟)
- 2014年山东省第五届ACM大学生程序设计竞赛--Hearthstone II(第二类Stirling数)
- angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)
- 山东省第五届ACM大学生程序设计竞赛-angry_birds_again_and_again(积分)
- 山东省第五届ACM大学生程序设计竞赛 Weighted Median
- “浪潮杯”山东省第五届ACM大学生程序设计竞赛(总结贴)
- 山东省第五届ACM大学生程序设计竞赛 Full Binary Tree
- 山东省第五届ACM大学生程序设计竞赛-Full Binary Tree(二叉树&&求任意两节点路径)
- Weighted Median(山东省第五届ACM大学生程序设计竞赛 )
- 2014年山东省第五届ACM大学生程序设计竞赛解题报告
- Full Binary Tree(山东省第五届ACM大学生程序设计竞赛 )
- 2014年山东省第五届ACM大学生程序设计竞赛 E. Factorial
- 山东省第五届ACM大学生程序设计竞赛-Hearthstone II(组合数学-第二类Stirling数)
- 山东省第五届ACM大学生程序设计竞赛 Hearthstone II 组合数学 Stirling数
- Phone Number 2010年山东省第一届ACM大学生程序设计竞赛
- 山东省第七届ACM大学生程序设计竞赛 训练总结 [8/12] 待补