CF-1860C Game on Permutation题解】的更多相关文章

CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> using namespace std; int T; int n, x, a, b; int main() { cin >> T; while(T--) { cin >> n >> x >> a >> b; if(a > b) swap(a, b…
Description An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each number from 11 to nn exactly once. For example, the following arrays are permutations: [3,1,2][3,1,2] , [1][1] , [1,2,3,4,5][1,2,3,4,5] and [4,3,1,2][4,…
原题链接 题意简介 给定一个长度为 n 的排列 {1,2,3,...,n} .现有两种操作: 对某个区间 [l,r] 求和 将排列往后推 x 次 (按字典序) 其中 \(n,q \leq 2\times10^5 , x\leq 10^5\) . 思路分析 乍一看毫无思路. 因为排列变换是毫无疑问的暴力,变换后怎么维护区间和是一个非常玄妙的问题.好像没有什么特殊的维护技巧. 仔细观察数据范围:\(x\leq 10^5 , q\leq 2\times 10^5\) 这意味着 \(\sum x_i \…
H - A + B Strikes Back A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input The input co…
http://codeforces.com/contest/361/problem/B #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,k; int main() { while(scanf("%d%d",&n,&k)!=EOF) { if(n==k) { printf("-1\n"); con…
题面 这是我做的第一道概率DP题: 做完后发现没有后效性的DP是真的水: 在这里说主要是再捋顺一下思路: 设f[i][j]表示有i只白鼠,j只黑鼠是获胜的概率: 显然:f[i][0]=1; 然后分四种情况: 1.先手刚好拿到白鼠:概率是i/(i+j); 2.先手拿到黑鼠,后手拿到了白鼠:概率为0: 3.先手拿到了黑鼠,后手拿到了也黑鼠,并且跑的是白鼠:概率是::dp[i][j]=j/(i+j)∗(j−1)/(i+j−1)∗i/(i+j−2)∗dp[i−1][j−2]; 4.先手拿到了黑鼠,后手拿…
题面 这道题的数据范围一看就是dfs或状压啦~ 本文以状压的方式来讲解 f[i][j]表示目前的节点是i,已经经历过的节点的状态为j的简单环的个数: 具体的转移方程和细节请看代码: PS:(i&-i)的意义便是树状数组 #include <bits/stdc++.h> using namespace std; int n,m; ][]; ][]; long long ans; int main () { cin>>n>>m; ;i<=m;i++){ int…
传送门 题目大意 给你一个数列,再给你一个矩阵,矩阵的(i,j)如果为1就表示可以将i,j位置上的数交换,问任意交换之后使原数列字典序最小并输出. 解题思路 因为如果i与j能交换,j与k能交换,那么i与k相当于能直接交换,所以我们先使用传递闭包求出所有可以交换的情况.之后从第一个位置开始贪心,看它能跟后面哪个小于它的数交换. 代码 #include<iostream> #include<cstdio> #include<cstring> using namespace…
题目 Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well. There are n cities in Berland. People can travel between cities using two-di…
Problem - A Tomorrow is a difficult day for Polycarp: he has to attend \(a\) lectures and \(b\) practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them. While preparing for the university, Polycarp…