[CF98E]Help Shrek and Donkey
Description
有兩個人在博弈,總共有n+m+1張牌,每張牌上的數字各不相同且在[1,n+m+1]內。
先手有n張牌,後手有m張牌,有一張牌蓋在桌上。
每次操作者可以從兩種操作中選擇一種進行
1:猜桌上的牌是什麼,猜中就贏,猜錯就輸
2:指定一張牌,如果對手有這張牌就必須展示並棄掉
問先手贏和後手贏的概率
n,m<=1000
Solution
可以參考SAMfAKe的題解
注意這題的難點在於先手可以有欺騙操作,即指定自己有的牌
如果對手相信了那麼就輸了
那麼我們可以考慮設表示先手有n張牌,後手有m張牌,先手獲勝的概率
首先當n,m均>=1時我們是不會去猜的,這時的收益是嚴格劣的
先手有兩種選擇,我們稱為“指定”和“欺騙”,同時後手也有兩種心理,“相信”和“不信”
Ps:這裡的相信是指相信蓋著的牌是指出的那張
若先手選擇“指定”,後手選擇“相信”,那麼收益為
若先手選擇“指定”,後手選擇“不信”,那麼收益為
若先手選擇“欺騙”,後手選擇“相信”,那麼收益為1
若先手選擇“欺騙”,後手選擇“不信”,那麼收益為
現在設先手有p的概率選擇“指定”
若後手選擇“相信”,先手獲勝的概率為
若後手選擇“不信”,先手獲勝的概率為
後手肯定是想讓先手獲勝的概率儘量小,所以對於先手的p,後手肯定會選擇上述兩個式子中值較小的那個執行,而先手又想讓自己的勝率儘量高
注意到將p看作變數,上面兩個式子代表了兩條直線,且一條斜率>0另一條<0
那麼先手肯定會選擇交點處的那個p,代表兩人博弈的一個均衡點
納什均衡真的挺有趣的說~
Code
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef double db;
const int N=1e3+5;
int n,m;
db f[N][N];
bool vis[N][N];
db Dp(int n,int m) {
if (!n) return 1.0/(m+1);
if (!m) return 1;
if (vis[n][m]) return f[n][m];
vis[n][m]=1;
db f1=Dp(m-1,n),f2=Dp(m,n-1);
db k1=1.0*m/(m+1)*(1-f1)-1,k2=1.0*m/(m+1)*(1-f1)+1.0/(m+1)+f2-1;
db b1=1,b2=1-f2;
db x=(b2-b1)/(k1-k2);
return f[n][m]=x*k1+b1;
}
int main() {
scanf("%d%d",&n,&m);
db ans=Dp(n,m);
printf("%.10lf %.10lf\n",ans,1-ans);
return 0;
}
相關推薦
[CF98E]Help Shrek and Donkey
Description 有兩個人在博弈,總共有n+m+1張牌,每張牌上的數字各不相同且在[1,n+m+1]內。 先手有n張牌,後手有m張牌,有一張牌蓋在桌上。 每次操作者可以從兩種操作中選擇一種進行 1
【CF98E】Help Shrek and Donkey
方便 繼續 註意 ace max 完全 直接 printf 哪些 Portal --> CF98E Description 兩個人快樂玩牌(總共\(n+m+1\)張),\(A\)有\(n\)張牌,\(B\)有\(m\)張牌,還有一張反著放在桌面上,每個人都知道這\
【Codeforces 98E】 Help Shrek and Donkey 遊戲策略神題
html str 直線 最終 view lns 是否 最優 rip from http://www.cnblogs.com/MashiroSky/p/6576398.html A君有n張牌,B君有m張牌,桌上還有一張反扣著的牌,每張牌都不一樣。 每個回合可以做兩
Codeforces 98E Help Shrek and Donkey 納什均衡
題意 有n+m+1張牌,牌上的數字互不相同且均在[1,n+m+1]中。A有n張牌,B有m張牌,還有一張牌蓋在桌上。現在A和B輪流操作,當前操作的那一方有兩種操作: 猜蓋在桌上的牌是什麼,若猜對則直接獲勝
Biased AI: IBM OpenScale wants to help detect and fix it
One of artificial intelligence's known weaknesses is bias. Now a new platform by IBM aims to give businesses the tool to detect that bias -- and fix it. IB
Ask HN: Please help me understand why the SEC settled with Elon Musk and Tesla
I don't want to talk about Elon Musk or Tesla here (it's valid conversation topic, but there's been a lot said already). I strictly want to understand why
Help us continue creating opportunities in tech for our kids and minority groups
Hey guys so my twin brother Ronald and I are 21 year old minority co-founders that need your help!https://www.gofundme.com/twins-in-techWe were recently s
This AI Can Help Spot Biased Websites and False News
This AI Can Help Spot Biased Websites and False NewsWe should take a lesson from it.By Rob VergerAny fact-checker who works in the media has a straightforw
Can neural networks, deep learning and GPUs help your business now?
Events If you want to exploit machine learning and AI, the range of technologies and techniques available can appear dizzying. Luckily, there's just one we
Planned intermittent fasting may help reverse type 2 diabetes, suggest doctors: And cut out need for insulin while controlling b
Around one in 10 people in the US and Canada have type 2 diabetes, which is associated with other serious illness and early death. It is thought to cost t
Show HN: A Q&A Website for Feedback, Memes, Jokes, Info, and Help
Is the name a play on https://what-if.xkcd.com/?What does the HQ mean?Why should one use this site over the thousands of other sites for Q&A's? (askRed
Machine Learning and ITSM: Helping Help Desks IT News Africa
The field of machine learning is quite a hot topic. We know that this type of artificial intelligence (AI) provides computers with the ability to learn wit
How Humans and Dogs Evolved to Help Each Other
Relative to the age of the planet, dogs are new additions on Earth. Charles Darwin initially believed dogs were part of the genus Canis, which includes a v
Electrical properties of dendrites help explain our brain's unique computing power: Neurons in human and rat brains carry electr
Using hard-to-obtain samples of human brain tissue, MIT neuroscientists have now discovered that human dendrites have different electrical properties from
How automation and cloud data can help fish farmers: A story from e
How automation and cloud data can benefit fish farmersGibran Huzaifah of e-Fishery proves that even the fisheries sector can be disrupted by technologyCopy
Taxis Could Charge Themselves and Help Balance the Electric Grid
This story is for Medium members.Continue with FacebookContinue with GoogleMedium curates expert stories from leading publishers exclusively for members (w
Resurrection of ancient Z80 Exidy Sorcerer computer and a call for help to HN
Folks of HN. I'm trying to bring my Exidy Sorcerer back to life... & a call for help from anyone who knows anything about (old) electronics.Years ago I
Resurrection of Z80 Exidy Sorcerer and a Call for Help from HN
Folks of HN. I'm trying to bring my Exidy Sorcerer back to life... & a call for help from anyone who knows anything about (old) electronics. Years ago
Tell HN: Please help me get to $1000 monthly recurring income and be rewarded
Hey guys,Yesterday I launched my unlimited content-as-a-service (contentiskey.co) on IndieHackers (http://www.contentiskey.co)I have received lot's of ove
Help a student pay his tuition and save on an entrepreneureneurship masterclass
Important: Please note that I don't know the person behind the campaign and they don't know I'm posting this here, so send any questions you may have his w