E Everyone is bot(赛时已过)
假设已经选到n-p个人,那么第n-p+1人就绝对不会复读,因为如果他复读,则之后的人会无脑复读,导致自己被惩罚,所以第n-p+1人绝对不会复读
此时问题的规模就减小到n-p了,反复递归下去,最后只有n%p个人复读
G Good red-string
赛时思路其实没错,但可能写假了
从右往左扫,对于每个r来说,右边的e足够就跳过,否则将第一个?改为e
同理,从左往右扫,对于每个d来说,左边的e足够就跳过,否则将第一个?改为e
之后计算剩下?中r,e,d的个数,从左到右贪心的先放r,再放e,再放d
int n, m, k;
char s[N];
void solve()
{
cin >> s + 1;
n = strlen(s + 1);
m = n / 3;
int c = 0;
stack<int> Stk;
for (int i = 1; i <= n; i++)
{
if (s[i] == 'd') ++c;
if (s[i] == 'e') --c;
if (s[i] == '?') Stk.push(i);
if (c > 0)
{
if (!Stk.empty()) { s[Stk.top()] = 'e', Stk.pop(), --c; }
else { No; return; }
}
}
c = 0;
while (!Stk.empty()) Stk.pop();
for (int i = n; i >= 1; i--)
{
if (s[i] == 'r') ++c;
if (s[i] == 'e') --c;
if (s[i] == '?') Stk.push(i);
if (c > 0)
{
if (!Stk.empty()) { s[Stk.top()] = 'e', Stk.pop(), --c; }
else { No; return; }
}
}
int cr = 0, ce = 0, cd = 0;
for (int i = 1; i <= n; i++)
{
if (s[i] == 'r') ++cr;
if (s[i] == 'e') ++ce;
if (s[i] == 'd') ++cd;
}
for (int i = 1; i <= n; i++)
{
if (s[i] != '?') continue;
if (cr < m) { s[i] = 'r', ++cr; continue; }
if (ce < m) { s[i] = 'e', ++ce; continue; }
if (cd < m) { s[i] = 'd', ++cd; continue; }
}
cr = 0, ce = 0, cd = 0;
for (int i = 1; i <= n; i++)
{
if (s[i] == 'r') ++cr;
if (s[i] == 'e') ++ce;
if (s[i] == 'd') ++cd;
if (cr >= ce && ce >= cd) continue;
No; return;
}
cr = 0, ce = 0, cd = 0;
for (int i = n; i >= 1; i--)
{
if (s[i] == 'r') ++cr;
if (s[i] == 'e') ++ce;
if (s[i] == 'd') ++cd;
if (cr <= ce && ce <= cd) continue;
No; return;
}
Yes;
}
H Here is an Easy Problem of Zero-chan(赛时已过)
不同数直接累积2,5的因子的个数即可,这样就可以直接树形dp+ksm
对于当前节点来说,它的权值是它的父亲权值×父亲节点编号^(它父亲子树的节点个数-自身节点个数)
计算答案时再乘上自身编号^自身子树节点个数
据说暴力能过,但能用ksm为啥不用呢
J Jellyfish and its dream(赛时已过)
赛时代码巨丑啊
出现相差为2的数就相当于有一个隔板,如(0,2)(1,0)(2,1)
出现相差为1的数就可以消除一个隔板,如(0,1)(1,2)(2,0)
最终隔板数小于等于1即可
int n, m, k;
int a[N];
int b[N];
void solve()
{
cin >> n;
rep(i, 0, n - 1)cin >> a[i], b[i] = (a[i] - a[i - 1] + 3) % 3;
b[1] = (a[1] - a[n] + 3) % 3;
int cnt = 0;
rep(i, 1, n)if (b[i] == 2)cnt++;
else if (b[i] == 1)cnt--;
cout << YN(cnt <= 1) << endl;
}
M Maimai DX 2077(赛时已过)
模拟签到不补了