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 PQ, 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 PQ 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=3Q=2Q−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的更多相关文章

  1. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

  2. BZOJ 2705: [SDOI2012]Longge的问题

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2554  Solved: 1566[Submit][ ...

  3. Dividing a Chocolate(zoj 2705)

    Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...

  4. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  5. 【BZOJ】【2705】【SDOI2012】Longge的问题

    欧拉函数/狄利克雷卷积/积性函数 2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1275  Solv ...

  6. AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识

    链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...

  7. BZOJ 2705: [SDOI2012]Longge的问题 GCD

    2705: [SDOI2012]Longge的问题 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnl ...

  8. bzoj 2705: [SDOI2012]Longge的问题 歐拉函數

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1035  Solved: 669[Submit][S ...

  9. Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1959  Solved: 1229[Submit][ ...

随机推荐

  1. BZOJ1875: [SDOI2009]HH去散步 图上边矩乘

    这道题十分的坑…… 我作为一只连矩乘都不太会的渣渣看到这道题就只能神搜了….. 首先说一下普通的矩乘求方案,就是高出邻接矩阵然后一顿快速幂….. 矩乘一般就是一些秘制递推….. 再说一下这道题,我们可 ...

  2. mysql5.7.22以上版本忘记密码时这样修改

    1.关闭mysql服务 net stop mysql 2.找到mysql安装路径找到 my.ini 打开在 [mysqld] 下添加 skip-grant-tables 跳过密码校验 3.登陆mysq ...

  3. Faster R-CNN教程

    Faster R-CNN教程 最后更新日期:2016年4月29日 本教程主要基于python版本的faster R-CNN,因为python layer的使用,这个版本会比matlab的版本速度慢10 ...

  4. 【转载】How long is “too long” for MySQL Connections to sleep?

    From:http://dba.stackexchange.com/questions/1558/how-long-is-too-long-for-mysql-connections-to-sleep ...

  5. 小程序根据input输入,动态设置按钮的样式

    [需求]实现当手机号已填写和协议已勾选时,“立即登录”按钮变亮,按钮可点击:若有一个不满足,按钮置灰,不可点击:实现获取短信验证码,倒计时提示操作:对不满足要求内容进行toast弹窗提示. <v ...

  6. 一个IT中专生在深圳的9年辛酸经历

    一个IT中专生在深圳的9年辛酸经历 想一想来到深圳已经近10年了,感概万千呐!从一个身无分文的中专职校计算机毕业出来后,竟然大胆的南下(之前可是连我们那地区之外都没去过),现在有供完的房子,温柔的妻子 ...

  7. Git菜鸟

    1.git 和svn的差异 git和svn 最大的差异在于git是分布式的管理方式而svn是集中式的管理方式.如果不习惯用代码管理工具,可能比较难理解分布式管理和集中式管理的概念.下面介绍两种工具的工 ...

  8. RGB颜色原理

    参考:http://www.cnblogs.com/harrytian/archive/2012/12/12/2814210.html 工作中经常和颜色打交道,但却从来没有从原理上了解一下,这篇文章希 ...

  9. python发布包到pypi的踩坑记录

    前言 突然想玩玩python了^_^ 这篇博文记录了我打算发布包到pypi的踩坑经历.python更新太快了,甚至连这种发布上传机制都在不断的更新,这导致网上的一些关于python发布上传到pypi的 ...

  10. kuangbin带你飞 后缀数组 题解

    2份模板 DC3 . 空间复杂度O3N 时间复杂度On #define F(x) ((x) / 3 + ((x) % 3 == 1 ? 0 : tb)) #define G(x) ((x) < ...