您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm 省赛题目
相关文章推荐