Contest Info


[Practice Link](https://codeforc.es/contest/1178)

Solved A B C D E F1 F2 G H
6/9 O O O O O Ø - - -
  • O 在比赛中通过
  • Ø 赛后通过
  • ! 尝试了但是失败了
  • - 没有尝试

Solutions


A. Prime Minister

签到题。

#include <bits/stdc++.h>
using namespace std; #define N 110
int n, a[N], b[N]; int main() {
while (scanf("%d", &n) != EOF) {
memset(b, 0, sizeof b);
int sum = 0, other = 0;
for (int i = 1; i <= n; ++i) scanf("%d", a + i), sum += a[i];
b[1] = 1;
other = a[1];
for (int i = 2; i <= n; ++i) {
if (a[1] >= a[i] * 2) {
other += a[i];
b[i] = 1;
}
}
if (other > sum / 2) {
int sze = 0;
vector <int> vec;
for (int i = 1; i <= n; ++i) {
if (b[i]) {
++sze;
vec.push_back(i);
}
}
printf("%d\n", sze);
for (int i = 0; i < sze; ++i) printf("%d%c", vec[i], " \n"[i == sze - 1]);
} else {
puts("0");
}
}
return 0;
}

B. WOW Factor

题意:

将连续的两个\(v\)可以看成一个\(w\),询问给出的字符串中只包含字符\(v\)和\(o\),询问有多少个子序列组成\(wow\)

思路:

先处理出每个\(o\)左边有多少个\(w\)以及右边有多少个\(w\),然后计算贡献即可。

代码:

#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 1000010
int n;
ll l[N], r[N];
char s[N]; int main() {
while (scanf("%s", s + 1) != EOF) {
n = strlen(s + 1);
l[0] = 0;
for (int i = 1; i <= n; ++i) {
l[i] = l[i - 1];
if (i > 1 && s[i] == 'v' && s[i - 1] == 'v') {
++l[i];
}
}
r[n + 1] = 0;
for (int i = n; i >= 1; --i) {
r[i] = r[i + 1];
if (i < n && s[i] == 'v' && s[i + 1] == 'v') {
++r[i];
}
}
ll res = 0;
for (int i = 1; i <= n; ++i) {
if (s[i] == 'o') {
res += 1ll * l[i - 1] * r[i + 1];
}
}
printf("%lld\n", res);
}
return 0;
}

C. Tiles

题意:

有这样的瓷砖:



用来拼\(n \cdot m\)的地板,要求任意相邻的边两边的颜色不能相同。

思路:

显然第一个位置可以有四种选择,并且第一排的后面的每个位置都有两种选择,因为不能和前面的边相同。

那么第一列后面的位置也有两种选择,那么剩下的位置都只有一种选择,因为它们相邻了两条边。

所以答案就是\(4 \cdot 2^{n + m - 2}\)

代码:

#include <bits/stdc++.h>
using namespace std; #define ll long long
const ll p = 998244353; ll qmod (ll base, ll n) {
ll res = 1;
while (n) {
if (n & 1) {
res = res * base % p;
}
base = base * base % p;
n >>= 1;
}
return res;
} int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF) {
printf("%lld\n", qmod(2, n - 1) * qmod(2, m - 1) % p * 4 % p);
}
return 0;
}

D. Prime Graph

题意:

给出\(n\)个点,要求构成一个简单图,使得边的总数是素数,并且每个点的度数也是素数。

思路:

  • 首先考虑每个点的度数至少为\(2\),那么先把这些点连成一个环,所有点的度数就是\(2\)了。
  • 再考虑边的数量是素数,一个显然的想法是所有数都可以表示成\(2x + 3y\)的形式,所以我们将环中的点分成两部分,每次各取一个点连边,就增加一条边,并且让两个度数为\(2\)的点变成度数为\(3\)的。
  • 那么只要满足我们找一个\(>= n\)的最近的素数\(y\),使得\(y - n \leq \frac{n}{2}\)即可这样构造。
  • 素数的密度很高,或者\(n\)只有\(1000\)可以打表验证一下,这样是可以的。

代码:

#include <bits/stdc++.h>
using namespace std; #define N 1010
#define pii pair <int, int>
#define fi first
#define se second
int n; bool isprime(int x) {
for (int i = 2; i < x; ++i) {
if (x % i == 0) return 0;
}
return 1;
} int main() {
while (scanf("%d", &n) != EOF) {
int tot = n;
for (int i = tot; ; ++i) {
if (isprime(i)) {
tot = i;
break;
}
}
vector <pii> vec;
for (int i = 2; i <= n; ++i) vec.push_back(pii(i - 1, i));
vec.push_back(pii(1, n));
int remind = tot - n;
int pos = n / 2 + 1;
for (int i = 1; i <= remind; ++i) {
vec.push_back(pii(i, pos));
++pos;
}
printf("%d\n", tot);
for (auto it : vec) printf("%d %d\n", it.fi, it.se);
}
return 0;
}

E. Archaeology

题意:

给出一个只包含'a', 'b', 'c'的字符串,保证任意两个连续的字符都不相同,要求选出一个子序列\(t\)使得它是一个回文串,并且\(|t| \geq \left\lfloor \frac{|s|}{2} \right\rfloor\)

思路:

贪心从两端取即可。

因为左端的两个字符和右端的两个字符,必然会有两个相等,因为保证了任意两个连续的字符不同,那么这样就是说每\(4\)个字符,至少有\(2\)个有贡献,显然满足题目限制。

其实也可以枚举一样,看看:

假如左端的\(ab\),那么右端的取值有以下几种:

  • \(ab\)
  • \(ac\)
  • \(bc\)

    显然都满足要求。

代码:

#include <bits/stdc++.h>
using namespace std; #define N 1000010
#define INF 0x3f3f3f3f
int n, m, f[N][3], g[N][3], nx[3];
char s[N], t[N];
int vis[N]; bool ok() {
m = 0;
for (int i = 1; i <= n; ++i) if (vis[i]) {
t[++m] = s[i];
}
t[m + 1] = 0;
if (m >= n / 2) {
printf("%s\n", t + 1);
return 1;
}
return 0;
} int main() {
while (scanf("%s", s + 1) != EOF) {
n = strlen(s + 1);
for (int i = 1; i <= n; ++i) vis[i] = 0;
nx[0] = nx[1] = nx[2] = 0;
for (int i = 1; i <= n + 1; ++i) {
for (int j = 0; j < 3; ++j) {
g[i][j] = nx[j];
}
if (i <= n) {
nx[s[i] - 'a'] = i;
}
}
nx[0] = nx[1] = nx[2] = n + 1;
for (int i = n; i >= 0; --i) {
for (int j = 0; j < 3; ++j) {
f[i][j] = nx[j];
}
if (i > 0) {
nx[s[i] - 'a'] = i;
}
}
int l = 0, r = n + 1;
while (l <= r) {
int Min = INF, pos = -1;
for (int i = 0; i < 3; ++i) {
if (f[l][i] < g[r][i] && f[l][i] - l + r - g[r][i] < Min) {
Min = f[l][i] - l + r - g[r][i];
pos = i;
}
}
if (pos == -1) break;
l = f[l][pos];
r = g[r][pos];
vis[l] = vis[r] = 1;
}
if (l < r - 1) {
vis[l + 1] = 1;
}
if (!ok()) printf("IMPOSSIBLE\n");
}
return 0;
}

F1. Short Colorful Strip

题意:

有一个长度为\(n\)的方格纸,现在要求做\(n\)次涂刷操作,每次选择一个区间将其刷成颜色\(i\),刚开始全都为颜色\(0\),问最后方格纸上第\(i\)格颜色为\(c_i\)的方案数。

\(n = m\)。

思路:

令\(f[l][r]\)表示完成区间\([l, r]\)的涂刷的方案数。

考虑对于一个区间\([l, r]\),那么我们第一次涂的肯定是\(c_i\)最小的,然后以\(c_i\)最小的那个格子为界,划分成两边,令\(pos[i]\)表示当前区间\(c_i\)最小的格子的下标,那么有转移方程:

\[\begin{eqnarray*}
f[l][r] = \sum\limits_{a} \sum\limits_{b} f[l][a - 1] \cdot f[a][pos[i] - 1] \cdot f[pos[i] + 1][i - 1] \cdot f[i +1][r]
\end{eqnarray*}
\]

注意到划分出两个区间后,左边右边独立,所以可以分开计算,最后乘起来即可。

代码:

#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 510
const ll p = 998244353;
int n, m, a[N];
ll f[N][N]; void add(ll &x, ll y) {
x += y;
if (x >= p) x -= p;
} ll dp(int l, int r) {
if (l > r) return 1;
if (f[l][r] != -1) return f[l][r];
if (l == r) return f[l][r] = 1;
f[l][r] = 0;
int pos = l;
for (int i = l + 1; i <= r; ++i) {
if (a[i] < a[pos]) pos = i;
}
ll L = dp(l, pos - 1), R = dp(pos + 1, r);
for (int i = l; i < pos; ++i) {
add(L, dp(l, i) * dp(i + 1, pos - 1) % p);
}
for (int i = pos + 1; i <= r; ++i) {
add(R, dp(pos + 1, i) * dp(i + 1, r) % p);
}
return f[l][r] = L * R % p;
} int main() {
while (scanf("%d%d", &n, &m) != EOF) {
memset(f, -1, sizeof f);
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
printf("%lld\n", dp(1, n));
}
return 0;
}

Codeforces Global Round 4的更多相关文章

  1. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  2. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  3. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  4. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  5. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  6. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  7. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  8. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  9. 【Codeforces Round 1110】Codeforces Global Round 1

    Codeforces Round 1110 这场比赛只做了\(A\).\(B\).\(C\),排名\(905\),不好. 主要的问题在\(D\)题上,有\(505\)人做出,但我没做出来. 考虑的时候 ...

  10. 树形DP ---- Codeforces Global Round 2 F. Niyaz and Small Degrees引发的一场血案

    Aspirations:没有结果,没有成绩,acm是否有意义?它最大的意义就是让我培养快速理解和应用一个个未知知识点的能力. ————————————————————————————————————— ...

随机推荐

  1. docker 实践五:端口映射和容器互联

    本篇是关于 docker 容器的端口映射和容器之间的互联内容. 注:环境为 CentOS7,docker 19.03. docker 的容器除了能连接网络外,在许多时候,我们需要让多个容器来协同完成任 ...

  2. UOJ #7 NOI2014购票(点分治+cdq分治+斜率优化+动态规划)

    重写一遍很久以前写过的题. 考虑链上的问题.容易想到设f[i]为i到1的最少购票费用,转移有f[i]=min{f[j]+(dep[i]-dep[j])*p[i]+q[i]} (dep[i]-dep[j ...

  3. 玩转【Mock.js】,前端也能跑的很溜

    现在开发已经是前后端分离了,前端和后端可以同时进行开发,互不影响,但是有些时候后端开发的接口慢于前端,导致前端需要等待后端的接口完成才能完成前后端对接,为了解决这个痛点,出现了模拟接口数据的方案,目前 ...

  4. jmeter中生成UUID作为唯一标识符

    在测试过程中,我们有时候需要一个唯一不重复的值(比如order_id).我之前一直用的时间戳+计数器/随机函数拼接,但是有时候效果不太好,今天知道了UUID这玩意,可以来操作下.jmeter也提供了U ...

  5. SQL Server2008导入导出数据库

    一.导出数据库 1.新建一个.bak的文本 右击数据库-->Tasks-->BackUp-->Remove原来的数据库-->Add后选择之前建立的.bak档 二.导入数据库 1 ...

  6. 关于/var/log/maillog 时间和系统时间不对应的问题 -- 我出现的是日志时间比系统时间慢12个小时

    那么让我们来见证奇迹的时刻吧!! 首先你要看下/etc/localtime的软连接,到哪了 一般就是这块出问题了 检查这里就绝对不会错的 对比图 : 这种情况, 删除/etc/localtime : ...

  7. 1+x证书学习日志——css常用属性

     ## css常用属性:             1:文本属性:                 文本大小:  font-size:18px;                 文本颜色    colo ...

  8. 【转载】2018年最值得期待的5大BPM厂商

    部署BPM软件可以帮助企业获得竞争优势,通过分析.设计.执行.控制和调节业务流程协助企业领导者提高组织绩效. 业务流程管理(BPM)是指随着公司和组织的发展匹配业务目标和流程的行为.部署BPM软件可以 ...

  9. U-Boot补丁 S3C2440

    # tar xvf u-boot-1.1.6.tar.bz2 //解压 # cd u-boot-1.1.6/ 制作补丁文件 # diff -urN u-boot-1.1.6 u-boot-1.1.6. ...

  10. python selenium测试用例断言

    1.if ...else ...判断进行断言 #coding=utf-8 from time import * from selenium import webdriver "): driv ...