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][ ...
随机推荐
- MySQL使用笔记(七)排序和限制数据记录查询
By francis_hao Dec 17,2016 排序数据记录查询 排序是指将筛选出符合条件的数据进行有序排放,有升序(ASC(默认))方式和降序(DESC)方式. mysql> se ...
- angular-translate加载.json文件进行翻译
这是这个demo的目录结构,总共有两个文件:locale-chinese.json和translation11.html locale-chinese.json文件的内容是: { "beau ...
- Windows2008 – Task Scheduler – ‘Action “C:\Windows\SYSTEM32\cmd.exe” with return code 1’
Remediation Edit Task Let us make the necessary changes, which is to specify the Start folder. Here ...
- Spring学习--通过注解配置 Bean (二)
在 classpath 中扫描组件: 当在组件类上使用了特定的注解之后 , 还需要在 Spring 的配置文件中声明 <context:component-scan>: base-pack ...
- iOS12、iOS11、iOS10、iOS9常见适配
作者:花丶满楼 链接:https://juejin.im/post/5c49a7d0518825254e4d46fc 一.iOS12(Xcode10) 1.1.升级Xcode10后项目报错 不允许多个 ...
- HDFS 的Trash回收站
1)在core-site.xml文件中添加这个配置 在每个节点(不仅仅是主节点)上添加配置 core-site.xml,增加如下内容 <property> <name>fs.t ...
- Bzoj4197 寿司晚宴
Description 为了庆祝 NOI 的成功开幕,主办方为大家准备了一场寿司晚宴.小 G 和小 W 作为参加 NOI 的选手,也被邀请参加了寿司晚宴. 在晚宴上,主办方为大家提供了 n−1 种不同 ...
- bzoj 4999: This Problem Is Too Simple!
Description 给您一颗树,每个节点有个初始值. 现在支持以下两种操作: 1. C i x(0<=x<2^31) 表示将i节点的值改为x. 2. Q i j x(0<=x&l ...
- Django【进阶】
FBV和CBV http://www.cnblogs.com/lucaq/p/7565560.html 中间件 http://www.cnblogs.com/lucaq/p/7581234.html ...
- C++中 相对路径与绝对路径 斜杠 '/' 与反斜杠 '\'的区别
文件路径正斜杠和反斜杠 正斜杠,又称左斜杠,符号是"/":反斜杠,也称右斜杠,符号是"\".文件路径的表示可以分为绝对路径和相对路径: 1.绝对路径表示相对容易 ...