[2013 Codejam Round 1B Problem B] 呵呵。。。

题目叙述(version xiaodao):

就是有一个水晶
从无线高往下坠落
如果有障碍
会等概率向两边滑
现在往下扔 n 个水晶
问某个位置有水晶的概率。

解法

按照如下方法,按照从低往高的顺序三角形两条直角边分层


那么(X , Y) 所在位置的层号也就是 (abs(X) + abs(Y)) / 2

我们可以看出每层的方块个数是 1 , 5 , 9 。。。。 4n + 1

那么分三种情况讨论:

1、如果n达不到 (X , Y) 层 , 那么 0.0

2、如果n超过 (X , Y) 层, 那么 1.0

3、如果 n 在 (X , Y) 层上

那么可以抽象为两个盒子,每个盒子里面最多装 (2 * 层数 + 1) 个球,球放进盒子的概率相等,问其中有一个盒子的球数 >= Y + 1 的概率

那么就是 二项式系数 , 预处理 (1 / 2)^ n * C[n][x] , 然后做一个累加即可

Code

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )

#define ALL(A) A.begin(), A.end()
#define BSC(A, x) (lower_bound(ALL(A), x) - A.begin())
#define CTN(T, x) (T.find(x) != T.end())
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
#define fi first
#define se second

typedef long long LL;


typedef vector<int> VI;
typedef map<int, int> MII;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;



template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T> inline void CLR(T &A){A.clear();}

//}

/** Constant List .. **/ //{

const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};

const int dx8[] = {-1, 0, 1, 0 , -1 , -1 , 1 , 1};
const int dy8[] = {0, 1, 0, -1 , -1 , 1 , -1 , 1};

const int dxhorse[] = {-2 , -2 , -1 , -1 , 1 , 1 , 2 , 2};
const int dyhorse[] = {1 ,  -1 , 2  , -2 , 2 ,-2 , 1 ,-1};

const int MOD = 1000000007;
//int MOD = 99990001;
const int INF = 0x3f3f3f3f;
const LL INFF = 1LL << 60;
const double EPS = 1e-9;
const double OO = 1e15;
const double PI = acos(-1.0); //M_PI;

//}

template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;}
//}
template<class T> inline T low_bit(T x) {return x & -x;}
/*****************************************************************/
int Case;
int X , Y , n;
const int N = 4009;
long double C[N][N];
void init(){
    C[0][0] = 1;
    C[1][0] = C[1][1] = .5;
    for (int i = 2 ; i < N ; ++i){
        C[i][0] = C[i][i] = C[i - 1][0] / 2.;
        for (int j = 1 ; j < i ; ++j)
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) / 2.;
    }
//    cout << C[3][3] << endl;
}
LL gao(LL x){
    LL y = x + 1;
    return (1 + 4ll * x + 1) * y / 2;
}
void solve(){
    scanf("%d%d%d" , &n , &X , &Y);
//    printf("%d %d %d\n" , n , X , Y);
    LL level = abs(X) + abs(Y);
    level /= 2;
    if (level == 0){
        printf("Case #%d: 1.0\n" , ++Case);
        return;
    }
    LL sum = gao(level);
    if (n >= sum){
        printf("Case #%d: 1.0\n" , ++Case);
        return;
    }
    if (X == 0){
        printf("Case #%d: 0.0\n" , ++Case);
        return;
    }
    LL pre = gao(level - 1);
    if (n <= pre){
        printf("Case #%d: 0.0\n" , ++Case);
        return;
    }
    n -= pre;
    long double ans = 0;
//    cout << n << endl;
    LL now = 2 * level + 1;
    long double all = 0;
    for (int i = 0 ; i <= n && i < now ; ++i) if (n - i < now) all += C[n][i];
    for (int i = abs(Y) + 1; i <= n && i < now ; ++i)if (n - i < now) ans += C[n][i];
    long double out = ans / all;
//    cout << ans << endl;
    printf("Case #%d: " , ++Case);
    cout << setiosflags(ios::fixed) << setprecision (9) << out << endl;
//    LL all =


}
int main(){
    freopen("B-large-practice.in" , "r" , stdin);
    freopen("Bmy.out" , "w" , stdout);
    init();
    int _;
    Case = 0;
    cin >> _;
    while(_--) solve();
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 JavaScript 编写的记忆游戏(附源代码)   项目:JavaScript 记忆游戏(附源代码) 记忆检查游戏是一个使用 HTML5、CSS 和 JavaScript 开发的简单项目。这个游戏是关于测试你的短期 记忆技能。玩这个游戏 时,一系列图像会出现在一个盒子形状的区域中 。玩家必须找到两个相同的图像并单击它们以使它们消失。 如何运行游戏? 记忆游戏项目仅包含 HTML、CSS 和 JavaScript。谈到此游戏的功能,用户必须单击两个相同的图像才能使它们消失。 点击卡片或按下键盘键,通过 2 乘 2 旋转来重建鸟儿对,并发现隐藏在下面的图像! 如果翻开的牌面相同(一对),您就赢了,并且该对牌将从游戏中消失! 否则,卡片会自动翻面朝下,您需要重新尝试! 该游戏包含大量的 javascript 以确保游戏正常运行。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox, 以获得更好、更优化的游戏体验。要玩游戏,首先,通过单击 memorygame-index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值