HDU 4599 Dice
2015-06-09 15:09
288 查看
Description
Given a normal dice (with 1, 2, 3, 4, 5, 6 on each face), we define:
F(N) to be the expected number of tosses until we have a number facing up for N consecutive times.
H(N) to be the expected number of tosses until we have the number '1' facing up for N consecutive times.
G(M) to be the expected number of tosses until we have the number '1' facing up for M times.
Given N, you are supposed to calculate the minimal M1 that G (M1) >= F (N) and the minimal M2 that G(M2)>=H(N)
Input
The input contains multiple cases.
Each case has a positive integer N in a separated line. (1<=N<=1000000000)
The input is terminated by a line containing a single 0.
Output
For each case, output the minimal M1 and M2 as required in a single line, separated by a single space.
Since the answer could be very large, you should output the answer mod 2011 instead.
Sample Input
Sample Output
Given a normal dice (with 1, 2, 3, 4, 5, 6 on each face), we define:
F(N) to be the expected number of tosses until we have a number facing up for N consecutive times.
H(N) to be the expected number of tosses until we have the number '1' facing up for N consecutive times.
G(M) to be the expected number of tosses until we have the number '1' facing up for M times.
Given N, you are supposed to calculate the minimal M1 that G (M1) >= F (N) and the minimal M2 that G(M2)>=H(N)
Input
The input contains multiple cases.
Each case has a positive integer N in a separated line. (1<=N<=1000000000)
The input is terminated by a line containing a single 0.
Output
For each case, output the minimal M1 and M2 as required in a single line, separated by a single space.
Since the answer could be very large, you should output the answer mod 2011 instead.
Sample Input
1 2 0
Sample Output
1 1 2 7 期望dp 主要是推公式http://www.cnblogs.com/allh123/archive/2013/08/25/3281039.html#include<cstdio> #include<cstring> #include<vector> #include<iostream> #include<queue> #include<algorithm> #include<cmath> #include<cstdlib> #include<string> using namespace std; const int base = 2011; const int size = 2; int n; int inv(int x) { if (x == 1) return 1; else return inv(base % x)*(base - base / x) % base; } int get(int x, int y) { int i, j; for (i = x, j = 1; y; y >>= 1) { if (y & 1) (j *= i) %= base; (i *= i) %= base; } return j; } void work(int n) { int x = get(6, n) - 1; int y = (((x+25) * inv(30) % base) + base) % base; int z = ((x * inv(5) % base) + base) % base; printf("%d %d\n", y, z); } int main() { while (scanf("%d", &n), n) work(n); }
相关文章推荐
- 计步器
- web前端讲解,jQuery之jQuery过滤器(二)内容过滤器
- 简述 synchronized 和 java.util.concurrent.locks.Lock 的异同 ?
- 使用block的一些注意点
- 在Ubuntu 12.04LTS系统中安装jdk和配置tomcat服务器
- 合并表格(Table)单元格
- 从通讯聊计算机
- 自定导航控制器
- 统计字符串的某一子串在字符串中的出现次数(C语言实现)
- 2015年16个最佳的免费响应式HTML5框架
- 测试keepalived备备模式的主从切换过程
- 张德芬《遇见未知的自己》--书评加读书笔记
- html jquery 相册资源搜集
- iOS代码适配(2)
- 被hao123恶意绑定了主页解决办法
- 用mac自带的safari浏览器下载excel文件后面自带了.exe后缀
- http状态码
- GRE写作满分:模仿范文
- python win7(64位)环境配置以及相关工具包的安装
- PCAP文件格式分析(做抓包软件之必备)