51nod 硬币游戏

有一个简单但是很有趣的游戏。在这个游戏中有一个硬币还有一张桌子,这张桌子上有很多平行线(如下图所示)。两条相邻平行线之间的距离是1,硬币的半径是R,然后我们来抛硬币到桌子上,抛下之后硬币有时候会和一些直线相交(相切的情况也算是相交),有时候不会。
请你来计算一下抛一次硬币之后,该硬币和直线相交数目的期望。

Input
第一行给出一个整数T,表示有T组数据(1<=T<=10000)。
第2行到T+1,每行给出一个整数R。(0< R <= 10,000,000,000)
Output
对于每一个数据,在一行中输出答案的整数部分即可。
Input示例
1
1
Output示例
2

这里写图片描述

求期望:EX=x1p1+x2p2+x3p3+…+xnpn
这里有两种情况:求与两条线相切,线段数目是n+1
不想切的线段数目是n.
相切的概率是P(切)=(2*r-n),E(切)=(2*r-n)*(n+1)
不想切的概率是是(0,n-2*r+1),无线趋近于1,P(不切)=(n-2*r+1),E(不切)=(n-2*r+1)*n
E(总)=E(切)+E(不切)=(n-2*r+1)*n+(n-2*r)*(n+1) = 2*r
也可以理解为:无数次抛,相切的概率无线趋近于1,不想切的概率为0.
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<ctime>
#include<string>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<cstdio>
#include<limits.h>
#define fir first
#define sec second
#define fin freopen("/home/ostreambaba/文档/input.txt", "r", stdin)
#define fout freopen("/home/ostreambaba/文档/output.txt", "w", stdout)
#define mes(x, m) memset(x, m, sizeof(x))
#define pii pair<int, int>
#define Pll pair<ll, ll>
#define INF 1e9+7
#define Pi 4.0*atan(1.0)
#define MOD 1000000007

#define lowbit(x) (x&(-x))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1

typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-12;
const int maxn = 4;
using namespace std;

inline int read(){
    int x(0),f(1);
    char ch=getchar();
    while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}

int main()
{
    int N, t;
    N = read();
    while(N--){
        t = read();
        printf("%lld\n", (ll)2*t);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值