AtCoder - 2705 Yes or No
Problem Statement
You are participating in a quiz with N+M questions and Yes/No answers.
It's known in advance that there are N questions with answer Yes and M questions with answer No, but the questions are given to you in random order.
You have no idea about correct answers to any of the questions. You answer questions one by one, and for each question you answer, you get to know the correct answer immediately after answering.
Suppose you follow a strategy maximizing the expected number of correct answers you give.
Let this expected number be P⁄Q, an irreducible fraction. Let M=998244353. It can be proven that a unique integer R between 0 and M−1 exists such that P=Q×R modulo M, and it is equal to P×Q−1 modulo M, where Q−1 is the modular inverse of Q. Find R.
Constraints
- 1≤N,M≤500,000
- Both N and M are integers.
Partial Score
- 1500 points will be awarded for passing the testset satisfying N=M and 1≤N,M≤105.
Input
Input is given from Standard Input in the following format:
N M
Output
Let P⁄Q be the expected number of correct answers you give if you follow an optimal strategy, represented as an irreducible fraction. Print P×Q−1 modulo 998244353.
Sample Input 1
1 1
Sample Output 1
499122178
There are two questions. You may answer randomly to the first question, and you'll succeed with 50% probability. Then, since you know the second answer is different from the first one, you'll succeed with 100% probability.
The expected number of your correct answers is 3 / 2. Thus, P=3, Q=2, Q−1=499122177 (modulo 998244353), and P×Q−1=499122178 (again, modulo 998244353).
Sample Input 2
2 2
Sample Output 2
831870297
The expected number of your correct answers is 17 / 6.
Sample Input 3
3 4
Sample Output 3
770074220
The expected number of your correct answers is 169 / 35.
Sample Input 4
10 10
Sample Output 4
208827570
Sample Input 5
42 23
Sample Output 5
362936761
wjz神犇省队集训的时候讲的神题!太笨了当时没有听懂,后来看了看课件懂QWQ
首先贪心策略比较显然,就是先选目前剩的多的类型。。
(先假设 n>=m 也就是 Yes > No)
然后选硬币就相当于在二维平面上行走,起点是(n,m),重点是(0,0),每次向左走代表选Yes,向下走代表选No。
当目前位置在 y=x 上方的时候,向下走会有1的贡献。
当目前位置的 y=x 下方的时候,向左走会有1的贡献。
当目前在 y=x 上的时候,怎么走都会有 1/2 的贡献(期望贡献)
所以我们就可以把在y=x和不在的贡献分开算。。。。
可以发现不在y=x的点的期望贡献总是n,因为当我们把y=x上方的路径对称下来的时候,可以发现不管怎么走,最后都一共向左走了n步。。
然后在y=x上的点的贡献就可以用期望的线性性拆开算了,对于每个点单独算经过它的概率,然后求和即可。
总的Yes/No 排列的种类显然是 C(n+m,n) 的,经过点(i,i) 的方案数则是 C(i*2,i) * C(n+m-i*2,n-i)的。
/* */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1000000,ha=998244353;
inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;}
inline void ADD(int &x,int y){ x+=y; if(x>=ha) x-=ha;} inline int ksm(int x,int y){
int an=1;
for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
return an;
} int jc[maxn+5],ni[maxn+5],n,m,ans; inline int C(int x,int y){ return x<y?0:jc[x]*(ll)ni[y]%ha*(ll)ni[x-y]%ha;} inline void init(){
jc[0]=1;
for(int i=1;i<=maxn;i++) jc[i]=jc[i-1]*(ll)i%ha;
ni[maxn]=ksm(jc[maxn],ha-2);
for(int i=maxn;i;i--) ni[i-1]=ni[i]*(ll)i%ha;
} inline void solve(){
for(int i=1;i<=m;i++)
ADD(ans,C(i<<1,i)*(ll)C(n+m-i*2,n-i)%ha); } int main(){
init(); scanf("%d%d",&n,&m);
if(n<m) swap(n,m); solve(); ans=ans*(ll)ni[2]%ha*(ll)ksm(C(n+m,n),ha-2)%ha; ADD(ans,n);
printf("%d\n",ans);
return 0;
}
AtCoder - 2705 Yes or No的更多相关文章
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- BZOJ 2705: [SDOI2012]Longge的问题
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2554 Solved: 1566[Submit][ ...
- Dividing a Chocolate(zoj 2705)
Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- 【BZOJ】【2705】【SDOI2012】Longge的问题
欧拉函数/狄利克雷卷积/积性函数 2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1275 Solv ...
- AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...
- BZOJ 2705: [SDOI2012]Longge的问题 GCD
2705: [SDOI2012]Longge的问题 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnl ...
- bzoj 2705: [SDOI2012]Longge的问题 歐拉函數
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1035 Solved: 669[Submit][S ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
随机推荐
- How do I see what character set a database / table / column is in MySQL?
Q: How do I see what the character set that a MySQL database, table and column are in? Is there some ...
- centos的网络设置问题
遭遇了多次centos的网络连接问题,现将正确配置总结下: 这里是使用vmware虚拟平台,因为涉及到中间这层,所以需要设置下: 保证centos也能连上网,首先物理机连上网,接着物理机的vmware ...
- egrep对于conf文件中去掉#注释,排除无用项
[root@localhost conf]# egrep -v "#|^$" nginx.conf.default > nginx.conf dd
- java简单发送邮件
需要的jar 据说是: <dependency> <groupId>javax.mail</groupId> <artifactId>mail</ ...
- lesson 4 再谈继承多态,抽象类和接口
再谈多态,抽象类和接口 上一次博客已经概念性的概述了继承多态,抽象类和接口,这次来具体的谈一谈他们之间的联系和需要注意的地方. 一.继承和多态:Inheritance (继承) & Polym ...
- 动态规划:状压DP
状压DP可以用在NP问题的小规模求解中(不理解,感觉和可以搜索的题很类似) 如果状态是个网格,数据范围很小,基本锁定状压DP 例题是BZOJ1725 题意是这样的,给定一个黑白图,然后种田,要求田与田 ...
- codechef T6 Pishty and tree dfs序+线段树
PSHTTR: Pishty 和城堡题目描述 Pishty 是生活在胡斯特市的一个小男孩.胡斯特是胡克兰境内的一个古城,以其中世纪风格 的古堡和非常聪明的熊闻名全国. 胡斯特的镇城之宝是就是这么一座古 ...
- [bzoj1031][JSOI2007]字符加密Cipher——后缀数组
Brief Description 给定一个长度为n的字符串,你需要对其进行加密. 把字符串围成一个环 显然从任意一个位置开始都可以有一个长度为n的串 把产生的n个串按字典序排序,把这n个串的最后一个 ...
- VC6.0显示行号的插件
VC6.0显示行号的插件,很好很强大的显行号插件,使用VC编程的朋友再也不用烦恼VC6.0没有行号的编程环境了. VC显示行号插件使用说明:1. 如果你的VC安装在C盘,请拷贝文件VC6LineNum ...
- Python3安装cx_Oracle连接oracle数据库实操总结
弄清版本,最重要!!! 首先安装配置时,必须把握一个点,就是版本一致!包括:系统版本,python版本,oracle客户端的版本,cx_Oracle的版本,然后安装配置就容易了! 如果已经安装Pyth ...