数学期望,I - Beating the Dataset,Light OJ 1274

Description

You are in a contest, and unfortunately you don't have much time. You have one problem in hand; you just glanced at the sample output and found that it just wants 'YES' or 'NO'. So, you have made another plan instead of solving the problem as you know the system very well.

For this problem, every test case is stored in a separate file. When a submission is found, the system successively runs the solution on all tests of a problem, and for each test the checking process goes as follows. The input is copied to the file input.txt. Then the solution is launched. It reads the input from the file input.txt and writes the result to the file output.txt. When it finishes, the correct answer is copied to the file answer.txt. If the contents of the files answer.txt and output.txt match, the test is assumed to be passed; otherwise, the test is not passed.

So, you decided to write a program that would operate as follows. If the folder containing the program doesn't contain the file answer.txt (i.e. the program is run on the first test), then the program outputs "YES". Otherwise, the program outputs the contents of the file answer.txt. And before the contest, the sizes of the data files are given to you.

And it's clear that the size of the file with the answer "YES" is 3 bytes, the size of the file with the answer "NO" is 2 bytes, and all the variants of the order of tests are equally probable. Now you want to calculate the average number of tests that your solution won't pass.

Input

Input starts with an integer T (≤ 10), denoting the number of test cases.

Each case starts with a line containing two integers n (1 ≤ n ≤ 5000) and s (2n ≤ s ≤ 3n) where n denotes the number of data sets and s denotes the total size of the answer files.

Output

For each case, print the case number and the average number of tests your solution won't pass. Error less than 10-6 will be ignored.

Sample Input

4

3 7

1 2

1 3

4 10

Sample Output

Case 1: 2

Case 2: 1

Case 3: 0

Case 4: 2.5000000000

Hint

For the first case, one of the three answers is "YES" and two answers are "NO". If the order of tests is "YES-NO-NO", then your solution won't pass the second test only; if the order is "NO-YES-NO", then it will pass none of the tests; if the order is "NO-NO-YES", the solution won't pass the first and the third tests.



这题深深的打击了我,真tm智障。。。。

开始看题目都没看懂,还是看的题解才看懂题目。

然后想的方向又错了,看了将近一个小时。。。

这题是求全排列中在首字母前加个yes然后与原来的字符串匹配,看有几个不同的。

这题肯定是有规律的,因为yes和no的个数被确定的。并且我们只要求出第i个字符与i+1个字符不同的情况数;

如果是NO-YES或者YES-NO那么就能确定有一种不同,所以期望是x*y/(n*(n-1))*(n-1),乘以n-1是因为n个字符有n-1种22配对的情况,因为YES—NO和NO-YES是2中情况,所以还有乘以2;

再加上如果是NO为首字符的话也是不能匹配成功的,所以还要加上y/n;

然后合并得出ans=2*x*y+y/(x+y)

得出结论,数学期望题只要推得出公式代码贼短。。。。

ac代码:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
#define debug(x) cout<<#x<<'='<<x<<endl;
#define ya(x) scanf("%d",&x)
#define Cas(x) printf("Case %d: ",x)
#define wen(x) printf("%d\n",x)
#define FOR(T) for(int cas=1;cas<=T;cas++)
int main()
{
    int T;
    ya(T);
    FOR(T)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x=y-2*x;
        y=(y-3*x)/2;
        double ans=(2.0*x*y+y)/(x+y);
        Cas(cas);
        printf("%lf\n",ans);
    }
    return 0;
}


全部评论

相关推荐

昨天 10:23
已编辑
湖南师范大学 计调
太久没更新,前几天看到一条评论,说“牛客就是当年那群做题区毕业了开始找工作还收不住那股味”的群体。字里行间透着居高临下的评判,不是,他该不会以为自己很幽默?很犀利吧?作为在牛客混了不算短日子的用户,我感到的不只是被冒犯,更是一种深刻的悲哀——这种以“松弛感”为名,对另一种生存策略的轻蔑,颇有一种自己考不上大学早早出来混社会,嘲笑考上大学的人是书呆子,然后大言不惭地说:死读书有什么用,人脉和资源才是硬道理。我不知道说这个话的人,手头究竟握着多少真正管用的人脉与资源,也不知道他这么傲慢地说出“那股味”的时候,是站在哪一个巨人的肩膀上,才能如此“松弛从容”地俯视众生,还能品评出别人身上“没收住”的余...
淬月星辉:这种评论把正常的努力扭曲成卷😂,说白了就是自己不努力,看着身边努力的人一个个都事业有成了,自己的心里开始不平衡了,就发这种酸言酸语。牛客可以说是我用过那么多平台里社区氛围最好的论坛了,用了大半年了,基本上没见过有人吵架的,都是在互帮互助提建议,帮忙看简历的,帮忙选offer的,帮忙指点学习路线的,分享工作经验和趣事的,我觉得这才是互联网该有的样子。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务