Hdu 5346 MZL's game 2015ACM多校对抗赛第五场
来源:互联网 发布:笛子软件下载 编辑:程序博客网 时间:2024/05/16 05:11
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=5346
MZL's game
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 62 Accepted Submission(s): 44
Problem Description
MZL has n cute boys.They are playing a game♂.The game will run in turn
First,System choose an alive playerx randomly.Player x will be out of the game.
Then player x will attack all alive players in the game
When a player is attacked,1−p is the probability of he still lives,p is the probability of he dies
Now mzl wants to know:the probability of one player be out of the game and be attackedk times
You need to print the probability mod 258280327 for every k from 0 to n-1
According to Fermat Theory,xy mod 258280327=x*(y258280325) mod 258280327
p will be given in a special way
First,System choose an alive player
Then player x will attack all alive players in the game
When a player is attacked,
Now mzl wants to know:the probability of one player be out of the game and be attacked
You need to print the probability mod 258280327 for every k from 0 to n-1
According to Fermat Theory,
Input
The first line of the input contains a single number T , the number of test cases.
NextT lines, each line contains three integer n ,x ,y .p=xy
T≤5 , n≤2∗103 0≤x≤109 x+1≤y≤109 .
It is guaranteed that y and 258280327 are coprime.
Next
It is guaranteed that y and 258280327 are coprime.
Output
Sample Input
23 33 1009 23 233
Sample Output
172186885 210128265 223268793229582513 70878931 75916746 175250440 21435537 57513225 236405985 111165243 115953819Hintfor case 1: The probability of you live and not be attacked is 1/3 The probability of you live and be attacked for one time is: (2/3)*(0.33*0.67+0.67*0.67*(1/2))=8911/30000
Source
2015 Multi-University Training Contest 5
题意:
n个可爱的人在玩游戏,每一次系统随机选择一个活着 的人出局,并攻击其余的人,每个人受到攻击,有p的概率会死亡,(1-p)的概率会存活下来。然后,下一轮n-1个人重复这个游戏。(T_T死了的人仍在该轮中,还会被扁丝~~)
求一个人受到k次攻击并出局的概率
做法:
给n个人编号1-n,假设系统依次选择1,2,3,,,,出局(当然也要是活着才能被选择出局)
那么dp[i][j]表示第i编号受到j次攻击后出局的概率,转移分两种情况考虑,第j次攻击来自第i-1编号人和来自第i-1编号前面的人。
那么,第一种情况,第i-1编号存活下来了才能被选择出局然后去攻击第i个人,那么此人受到的攻击次数就是j-1次了;
第二种情况,第i-1编号人死了,要不然第j次攻击一定来自第i-1编号的人,此人受到的攻击次数和i一样,都是j次。(因为我固定了出局顺序!!!)
所以,转移方程:dp[i][j]=dp[i-1][j-1]*p1+dp[i-1][j]*p2
p1表示第i-1编号受j-1次攻击存活的概率,p2表示第i-1编号受j次攻击死亡的概率
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;#define LL long long#define MOD 258280327LL power(LL x,LL k){ LL res=1; while(k){ if(k&1)res=res*x%MOD; x=x*x%MOD; k>>=1; } return res;}LL dp[2100][2100];int main(){ LL n,x,y,T;scanf("%lld",&T); while(T--){ scanf("%lld%lld%lld",&n,&x,&y); LL dead=x*power(y,MOD-2)%MOD;//dead probability of an attack LL live=(MOD+1-dead)%MOD;//live probability of an attack dp[1][0]=1; for(int j=1;j<n;j++)dp[1][j]=0; for(int i=2;i<=n;i++){// i th peolivee dp[i][0]=0; LL tmp=1; for(int j=1;j<i;j++){// j times attacked //move = i th live (live^(j-1)) + i th dead (1-live^(j)) dp[i][j]=dp[i-1][j-1]*tmp%MOD+dp[i-1][j]*(MOD+1-tmp*live%MOD)%MOD; tmp=tmp*live%MOD; } } for(int k=0;k<n;k++){ LL tmp=1; LL ans=0; for(int i=1;i<=n;i++){ if(i-1<k)tmp=tmp*live%MOD; ans=(ans+dp[i][k])%MOD; } // ans*live^(k)/n ans=ans*tmp%MOD*power(n,MOD-2)%MOD; printf("%lld%c",ans,k==n-1?'\n':' '); } } return 0;}
0 0
- Hdu 5346 MZL's game 2015ACM多校对抗赛第五场
- Hdu 5344 MZL's xor 2015ACM多校对抗赛第五场
- Hdu 5347 MZL's chemistry 2015ACM多校对抗赛第五场
- Hdu 5349 MZL's simple problem 2015ACM多校对抗赛第五场
- Hdu 5350 MZL's munhaff function 2015ACM多校对抗赛第五场
- Hdu 5351 MZL's Border 2015ACM多校对抗赛第五场
- 2015ACM多校对抗赛第四场 hdu 5327
- 2015ACM多校对抗赛第四场 hdu 5328
- 2015ACM多校对抗赛第四场 hdu 5335
- 2015ACM多校对抗赛第四场 hdu 5336
- hdu 5344 MZL's xor (2015多校第五场第2题) 简单化简
- hdu 5349 MZL's simple problem (2015多校第五场第7题) multiset
- HDU 5351 MZL's Border(2015多校第五场第9题) 写长串找规律
- Hdu 5307 He is Fly 2015ACM多校对抗赛第二场
- hdu 5347 MZL's chemistry(2015多校第五场第5题)高中化学选修知识 第一电离能
- hdu 5344 MZL's xor (15多校第五场1002)
- hdu 5347 MZL's chemistry(15多校第五场1005)
- hdu 5348 MZL's endless loop(15多校第五场1006) 欧拉路
- C++ vector容器类型及初始化方法
- 南邮 OJ 1586 鸡兔同笼
- HDU 1242:Rescue 【bfs】
- epoll精髓
- 数据结构05:图
- Hdu 5346 MZL's game 2015ACM多校对抗赛第五场
- hdu 5349 MZL's simple problem 2015多校联合训练赛#5 简单题
- (C/C++学习笔记)指针做函数参数形成回调
- HDU 1272 小希的迷宫
- android 仿饿了么购物车
- 设计模式---Java源码中的设计模式
- 关于WCF配置文件的知识点讲解1
- Java多线程总结
- 南邮 OJ 1587 3n+1