Educational Codeforces Round 68
Contest Info
[Practice Link]()
| Solved | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 5/7 | O | O | O | O | Ø | - | - |
- O 在比赛中通过
- Ø 赛后通过
- ! 尝试了但是失败了
- - 没有尝试
Solutions
A.Remove a Progression
签到题。
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n, x;
scanf("%d%d", &n, &x);
printf("%d\n", x * 2);
}
return 0;
}
B.Yet Another Crosses Problem
签到题。
#include <bits/stdc++.h>
using namespace std;
#define N 100010
int n, m, a[N], b[N];
vector <vector<int>> G;
char s[N];
int main() {
int T; scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
G.clear(); G.resize(n + 1);
for (int i = 1; i <= n; ++i) a[i] = 0;
for (int i = 1; i <= m; ++i) b[i] = 0;
for (int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
G[i].resize(m + 1);
for (int j = 1; j <= m; ++j) {
if (s[j] == '*') {
G[i][j] = 1;
} else {
++a[i];
++b[j];
}
}
}
int res = n + m - 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (G[i][j]) {
res = min(res, a[i] + b[j]);
} else {
res = min(res, a[i] + b[j] - 1);
}
}
}
printf("%d\n", res);
}
return 0;
}
C.From S To T
题意:
有三个字符串\(s, t, p\),可以将\(p\)中的任意字符插入到\(s\)中的任意位置,问能否将\(s\)变成\(t\)。
思路:
首先\(s\)肯定是\(t\)的一个子序列,再判断\(p\)中的字符个数是否够插即可。
代码:
#include <bits/stdc++.h>
using namespace std;
#define N 110
char s[N], t[N], p[N];
int cnts[30], cntt[30], cntp[30], lens, lent, lenp;
int nx[30], f[N][30];
bool ok() {
for (int i = 0; i < 26; ++i) {
if (cnts[i] > cntt[i] || cnts[i] + cntp[i] < cntt[i]) return 0;
}
for (int i = 0; i < 26; ++i) nx[i] = lent + 1;
for (int i = lent; i >= 0; --i) {
for (int j = 0; j < 26; ++j) {
f[i][j] = nx[j];
}
if (i) nx[t[i] - 'a'] = i;
}
int it = 0;
for (int i = 1; i <= lens; ++i) {
it = f[it][s[i] - 'a'];
if (it == lent + 1) break;
}
return (it != lent + 1);
}
int main() {
int T; scanf("%d", &T);
while (T--) {
scanf("%s%s%s", s + 1, t + 1, p + 1);
lens = strlen(s + 1);
lent = strlen(t + 1);
lenp = strlen(p + 1);
memset(cnts, 0, sizeof cnts);
memset(cntt, 0, sizeof cntt);
memset(cntp, 0, sizeof cntp);
for (int i = 1; i <= lens; ++i) ++cnts[s[i] - 'a'];
for (int i = 1; i <= lent; ++i) ++cntt[t[i] - 'a'];
for (int i = 1; i <= lenp; ++i) ++cntp[p[i] - 'a'];
puts(ok() ? "YES" : "NO");
}
return 0;
}
D.1-2-K Game
题意:
有\(n\)个石头,每次可以移走\(1\)个,移走\(2\)个,或者移走\(k\)个,谁先不能移动谁输,问先手必胜还是后手必胜。
思路:
考虑没有移动\(k\)步的情况,那么显然有:
- \(n = 1\)为必胜态
- \(n = 2\)为必胜态
- \(n = 3\)为必败态
- \(n = 4\)为必胜态
- \(n = 5\)为必胜态
- \(n = 6\)为必败态
即\(n \equiv 0 \bmod 3\)时是必败态,否则是必胜态。
根据以下原则打表: - 当前状态指向的所有后继状态都是必胜态,那么当前状态是必败态
- 当前状态能够指向某一个必败态,那么当前状态是必胜态
发现:
\(k \neq 0 \bmod 3\)时,即为上述规律。
否则会出现循环节,即\(\frac{k}{3} - 1\)个\(NNP\),加一个\(NNNP\)。
其中\(N\)代表必胜态,\(P\)代表必败态。
代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
char *fi = "Alice";
char *se = "Bob";
int T, n, k; scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &k);
if (n == 0) puts(se);
else {
if (k % 3) {
if (n % 3 == 0) puts(se);
else puts(fi);
} else {
k /= 3;
int p = (k - 1) * 3 + 4;
n = (n - 1) % p + 1;
if (n <= (k - 1) * 3) {
if (n % 3 == 0) puts(se);
else puts(fi);
} else {
n -= (k - 1) * 3;
if (n == 4) puts(se);
else puts(fi);
}
}
}
}
return 0;
}
E.Count The Rectangles
题意:
给出一些二维平面上这样的线段:

问其中有多少个矩形?
思路:
考虑\(n^2\)枚举两条平行\(x\)轴的线,那么这两根线的贡献就是这两根线的交区间中竖线个数组成的区间个数。
那么考虑怎么计算竖线的个数。
可以按顺序取枚举,对于每一条竖线\((y_1, y_2, x)\),我们在\(y_1\)的时候加入它的贡献,\(y_2 + 1\)的时候删去它的贡献,用一个权值\(BIT\)维护一下即可。
代码:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 50100
#define pii pair <int, int>
#define fi first
#define se second
int n;
int x[N][2], y[N][2];
int b[N], c[N];
vector <vector<pii>> vec, add, del;
void Hash() {
sort(b + 1, b + 1 + b[0]);
sort(c + 1, c + 1 + c[0]);
b[0] = unique(b + 1, b + 1 + b[0]) - b - 1;
c[0] = unique(c + 1, c + 1 + c[0]) - c - 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 2; ++j) {
x[i][j] = lower_bound(b + 1, b + 1 + b[0], x[i][j]) - b;
y[i][j] = lower_bound(c + 1, c + 1 + c[0], y[i][j]) - c;
}
}
}
struct BIT {
int a[N];
void init() {
memset(a, 0, sizeof a);
}
void update(int x, int v) {
for (; x < N; x += x & -x) {
a[x] += v;
}
}
int query(int x) {
int res = 0;
for (; x > 0; x -= x & -x) {
res += a[x];
}
return res;
}
int query(int l, int r) {
if (l > r) return 0;
return query(r) - query(l - 1);
}
}bit;
ll C(int n) {
return 1ll * n * (n - 1) / 2;
}
int main() {
while (scanf("%d", &n) != EOF) {
b[0] = 0; c[0] = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d%d%d%d", x[i], y[i], x[i] + 1, y[i] + 1);
b[++b[0]] = x[i][0];
b[++b[0]] = x[i][1];
c[++c[0]] = y[i][0];
c[++c[0]] = y[i][1];
}
Hash();
vec.clear(); vec.resize(N);
add.clear(); add.resize(N);
del.clear(); del.resize(N);
for (int i = 1; i <= n; ++i) {
if (y[i][0] == y[i][1]) {
if (x[i][0] > x[i][1]) swap(x[i][0], x[i][1]);
vec[y[i][0]].push_back(pii(x[i][0], x[i][1]));
} else {
if (y[i][0] > y[i][1]) swap(y[i][0], y[i][1]);
add[y[i][0]].push_back(pii(x[i][0], y[i][1] + 1));
}
}
ll res = 0;
bit.init();
for (int i = 1; i <= c[0]; ++i) {
for (auto it : del[i]) {
bit.update(it.fi, -1);
}
for (auto it : add[i]) {
bit.update(it.fi, 1);
del[it.se].push_back(pii(it.fi, it.fi));
}
for (auto it : vec[i]) {
for (int j = i + 1; j <= c[0]; ++j) {
for (auto it2 : del[j]) {
bit.update(it2.fi, -1);
}
for (auto it2 : vec[j]) {
int l = max(it.fi, it2.fi), r = min(it.se, it2.se);
res += C(bit.query(l, r));
}
}
for (int j = i + 1; j <= c[0]; ++j) {
for (auto it2 : del[j]) {
bit.update(it2.fi, 1);
}
}
}
}
printf("%lld\n", res);
}
return 0;
}
Educational Codeforces Round 68的更多相关文章
- Educational Codeforces Round 68 E. Count The Rectangles
Educational Codeforces Round 68 E. Count The Rectangles 传送门 题意: 给出不超过\(n,n\leq 5000\)条直线,问共形成多少个矩形. ...
- Educational Codeforces Round 68 差G
Educational Codeforces Round 68 E 题意:有 n 个线段,每个都是平行 x 或者 y 轴,只有互相垂直的两线段才会相交.问形成了多少个矩形. \(n \le 5000, ...
- Educational Codeforces Round 68 Editorial
题目链接:http://codeforces.com/contest/1194 A.Remove a Progre ...
- Educational Codeforces Round 68 (Rated for Div. 2)---B
http://codeforces.com/contest/1194/problem/B /* */ # include <bits/stdc++.h> using namespace s ...
- Educational Codeforces Round 68 (Rated for Div. 2)补题
A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...
- Educational Codeforces Round 68 (Rated for Div. 2) C. From S To T (字符串处理)
C. From S To T time limit per test1 second memory limit per test256 megabytes inputstandard input ou ...
- Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)
D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...
- Educational Codeforces Round 68 (Rated for Div. 2)D(SG函数打表,找规律)
#include<bits/stdc++.h>using namespace std;int sg[1007];int main(){ int t; cin>>t; while ...
- Educational Codeforces Round 68 (Rated for Div. 2)-D. 1-2-K Game
output standard output Alice and Bob play a game. There is a paper strip which is divided into n + 1 ...
随机推荐
- Scala 面向对象编程之类
定义一个简单的类 // 定义类,包含field以及方法 class HelloWorld { private var name = "leo" def sayHello() { p ...
- Detection综述
4月中旬开始,尝试对目标检测领域做一个了解,看了差不多6-7篇paper,在这里记录一下: 一.Detection简介 人脸检测的目标是找出图像中所有的人脸对应的位置,算法的输出是人脸外接矩形在图像中 ...
- source tree每次push都需要密码的解决方法
Windows首先可以考虑使用GitHub for Windows,它已经包含了该助手,或者可以下载对应系统的版本:Windows 7.Windows 8.Source 版本,然后解压缩文件并将里面的 ...
- arm的基本介绍
2440是arm9核,是基于v4 架构 6410是arm11核 基于v6架构 210是a8的核 基于v7架构 前面的是经典阵营,比较老.Arm11之后改为contex系列. Arm7的水准和M3相 ...
- Vue指令之`v-model`和`双向数据绑定
v-bind 只能实现数据的单向绑定,从 M 自动绑定到 V, 无法实现数据的双向绑定 <input type="text" v-bind:value="msg& ...
- 剖析gcc -v输出
分析gcc -v的详细信息的意义 首先我们需要清楚一点,我们并不能完全弄清楚gcc -v的所有信息,因为毕竟我们并不是GCC编译器集合的实现者,对于这些信息,他们才是最清楚的.由于我们不能将所有的信息 ...
- 在Linux中安装适用于arm64位的nodejs
# 安装适用于arm64位的nodejs runtime v10.16.3 mkdir /runtimes cd /runtimes wget https://nodejs.org/dist/v10. ...
- MOOC下载器的文档整理
1.背景 最近学习中国大学MOOC的课程,想把课程的pdf下载下来本地保存并浏览.工具: Setup-Mooc-3.4.0.exe 但是,却发现所下载的文档在不同的文件夹里,浏览很不方便.于是 ...
- 复杂json后端解析出现第二层无数据的问题
自从使用了lombok之后写代码更加爽了 但是突然遇到前端小姐姐传的对象中的数组后端接收不到,查了好长时间无果后就搁置了. 今天突然想找找什么原因.自己写了一个测试的案例,经过测试过后发现是lombo ...
- 服务器上 MySql 8.0.16创建远程连接账号、获取初始密码、修改密码、重启命令等
一. 创建远程连接账号 1. 终端连接服务器 ssh -p 端口号 用户名@ip地址 例如:ssh -p 22 yyy@1.2.3.4 2.进入mysql mysql -u 用户名 -p 然后输入密码 ...