cf540D. Bad Luck Island(概率dp)
题意
岛上有三个物种:剪刀$s$、石头$r$、布$p$
其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀
每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉)
问最后仅有$s/r/p$物种生存的概率
Sol
还是想复杂了啊,我列的状态时$f[i][j], g[i][j],t[i][j]$分别表示第$i$天,$j$个$s, r, p$活着的概率
然而转移了一下午也没转移出来。。
标算比我简单的多,直接设$f[i][j][k]$表示剩下$i$个$s$,$j$个$r$,$k$个$p$的概率
然后记忆化搜索一下
/* */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long
#define LL long long
#define ull unsigned long long
#define rg register
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e6 + , INF = 1e9 + , mod = 1e9 + ;
const double eps = 1e-;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
double a, b, c;
double f[][][];
double calca(int a, int b, int c) {
if(f[a][b][c]) return f[a][b][c];
if(a == ) return f[a][b][c] = ;
if(a && (!b) && (!c)) return f[a][b][c] = ;
double down = a * b + b * c + a * c, ans = ;
if(a && b) ans += (double) a * b / down * calca(a, b - , c);
if(b && c) ans += (double) b * c / down * calca(a, b, c - );
if(a && c) ans += (double) a * c / down * calca(a - , b, c);
return f[a][b][c] = ans;
}
double calcb(int a, int b, int c) {
if(b == ) return f[a][b][c] = ;
if((!a) && b && (!c)) return f[a][b][c] = ;
if(f[a][b][c]) return f[a][b][c];
double down = a * b + b * c + a * c, ans = ;
if(a && b) ans += (double) a * b / down * calcb(a, b - , c);
if(b && c) ans += (double) b * c / down * calcb(a, b, c - );
if(a && c) ans += (double) a * c / down * calcb(a - , b, c);
return f[a][b][c] = ans;
}
main() {
a = read(); b = read(); c = read();
double a1 = , a2 = ;
printf("%.10lf ", a1 = calca(a, b, c)); memset(f, , sizeof(f));
printf("%.10lf ", a2 = calcb(a, b, c));
printf("%.10lf", - a1 - a2);
return ;
}
/*
2 2 1
1 1
2 1 1
*/
cf540D. Bad Luck Island(概率dp)的更多相关文章
- Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP
D. Bad Luck Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/pr ...
- codeforces 540D Bad Luck Island (概率DP)
题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...
- CF540D Bad Luck Island(期望dp)
传送门 解题思路 比较容易的一道期望\(dp\),设\(f[i][j][k]\)表示石头\(i\)个,剪刀\(j\)个,步子\(l\)个.然后转移的时候用组合数算一下就好了. 代码 #include& ...
- Codeforces 540D Bad Luck Island - 概率+记忆化搜索
[题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...
- CF540D Bad Luck Island
嘟嘟嘟 看到数据范围很小,就可以暴力\(O(n ^ 3)\)dp啦. 我们令\(dp[i][j][k]\)表示这三种人分别剩\(i, j, k\)个的概率.然后枚举谁挂了就行. 这里的重点在于两个人相 ...
- 【CF540D】 D. Bad Luck Island (概率DP)
D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF#301 D:Bad Luck Island (概率dp)
D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j] ...
- CF 540D——Bad Luck Island——————【概率dp】
Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces B. Bad Luck Island(概率dp)
题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- 装饰器(Decorator)模式
public interface IDoThings { public void doSomeThing(); } public class DoThings implements IDoThings ...
- 查询时根据权限更改sql
import java.lang.reflect.Method; import org.apache.log4j.Logger; import org.springframework.aop.Meth ...
- 湖南省第十二届大学生计算机程序设计竞赛 problem A 2016
如果 a * b % 2016 == 0 如果a = 1 ,且 a * b % 2016 == 0 考虑一下a = 2017的时候 2017 * b = (2016 + 1) * b % 2016 = ...
- JVM垃圾收集器总结
前言: 了解了JVM垃圾回收算法之后就要说说垃圾收集器了. 一.三个概念 Stop-the-World:JVM执行任何一种GC算法时是会停止应用程序的执行的,所以大多数GC优化都是从减少Stop-th ...
- asp.net5开发中DNX SDK版本的影响
某次asp.net5开发中遇到了一个很奇怪的问题,引用部分的nuget包没有显示任何错误,如下图: 但是编译时出现了几百个错误: 错误基本都是形如“CS0246 The type or namespa ...
- Day3上
T1 星空[问题描述]你是能看到第一题的friends 呢.——hja点点星空是一张
- 提升Java代码质量(三)
Item7:覆盖equals时需要遵守通用约定 在我们日常开发过程中,重写equals是比较常用的,但存在许多不合适的覆盖方式导致错误,最好的避免方法就是不去重写equals.但有时我们的业务又需要建 ...
- java 基础 01 变量和注释、数据类型
1,变量和注释 比如:姓名:xiaoming 年龄:18 1.1变量的基本概念 当需要在程序中记录单个数据内容时,则需要声明一个变量来处理,而变量的本质就是内存中申请一块存储单元用于存储数据内容,由于 ...
- Google常用拓展插件
1.web前端助手(FEhelper)提供一些实用的前端小工具,功能十分贴心 2.bookMarks Manager 一个书签管理工具 3.Clear Cache 清除浏览器的缓存,有很多供选择的条目 ...
- Android 浮动按钮的伸缩效果
在做项目时想增加点动感,于是就有如下效果: 实现起来也很简单,通过属性动画和recyclerview 滑动结合就很好实现了. 通过给recycleview添加一个滑动监听:通过滚动的差值来处理动画 m ...