从大到小,枚举所有最大值。 对于每个最大值,计算可以达到的最大值。 代码 官方 #include <iostream> #include <algorithm> #include <set> #include <stack> #include <vector> using namespace std; void solve() { int N = 0; cin >> N; int ans = 0; vector<int> pr; pr.assign(N * N, ...
初始化的时候要注意,一开始没初始化,调试了很久 #include<bits/stdc++.h>usingnamespacestd; typedeflonglongll;constintinf=1e18;constintmaxn=3e5+7;constintmod=1e9+7;#definemem0(a) memset(a,0,sizeof(a))#definememinf(a) memset(a,0x3f,sizeof(a))#definels rt<<1#definers rt<<1|1#de...
Another Permutation Problem 我的赛时做法是官方题解的做法(M就是枚举i×j),但是维护用的是并查集;官方题解的维护应该是这样的:从n倒序枚举到1,对于当前数字,找到小于Mx的还没被用过的最大的数字,我们维护一个栈,观察到Mx单调递增,于是每次我们将新增加的可行的数放进栈里面,然后弹出栈顶即可 然后看看洛谷题...
But why is it that when we take the top 2 elements of the stack we have both permutations p and q (If they are in the same permutation, the solution is wrong). Well, how about we look at the case when we push elements in the stack. That's the case with f[i] = 2. We see ...
【Gym 100015A】Another Rock-Paper-Scissors Problem 题意 Sonny出石头剪刀布的猜拳策略是 先出R,然后每连续两段都是打败前一段的出拳, 现在问你第n回合打败他要出什么。 分析 如果n是介于3的某个次方的(1,2]倍,那就是n要打败n减去这个次方对应的拳,故+1(对应的是P就变成S,S就变成R,R就变成P)...
D. Yet Another Inversions Problem You are given a permutation $p_0, p_1, \ldots, p_{n-1}$ of odd integers from $1$ to $2n-1$ and a permutation $q_0, q
如果n是介于3的某个次方的(1,2]倍,那就是n要打败 n减去这个次方 对应的拳,故+1(对应的是P就变成S,S就变成R,R就变成P) 如果是(2,3]倍,那就+2(P变成R,R变成S,S变成P)。 而我们要知道 n减去这个次方 对应的拳,就用递归去求了。 可以用数组储存3的次方,数据范围n<=10^12,log310^12=25.15.....