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 ...
随机推荐
- C#简单工厂案例
using System; namespace Application { class JianDanGongChang { static void Main(string[] args) { Fac ...
- linux的scp命令可以在linux服务器之间复制文件和目录
scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的.可能会稍微影响一下速度.当你服务器 ...
- threejs CameraHelper 查看照相机的观察范围
简单例子 这个例子,是在一个视图中,看到照相机的辅助线,也就是,一个照相机的观察访问 这样,就需要两个照相机,一个是主照相机,一个是加有辅助线的照相机(有两种,正交和透视,这里辅助的使用的是正交的) ...
- R_数据视觉化处理_中阶_05
条形图:条形图通过垂直或水平的条形展示了类型变量的分布(频数).最简单的用法为:barplot(height),height为矩阵或向量. horiz=TRUE选项:表示水平,在此之前先使用table ...
- 用scrapy爬取京东商城的商品信息
软件环境: gevent (1.2.2) greenlet (0.4.12) lxml (4.1.1) pymongo (3.6.0) pyOpenSSL (17.5.0) requests (2.1 ...
- python简单页面爬虫入门 BeautifulSoup实现
本文可快速搭建爬虫环境,并实现简单页面解析 1.安装 python 下载地址:https://www.python.org/downloads/ 选择对应版本,常用版本有2.7.3.4 安装后,将安装 ...
- 基于FTP 的本地Yum服务器配置
服务器端 环境如下 Vmware14CentOS 7.6 192.168.20.81 server 192.168.20.81 client 1.配置yum源 mount /dev/cdrom /me ...
- Ubuntu16.04, CUDA8 CUDNN6 下安装 Tensorflow-gpu, Keras, Pytorch, fastai
如何访问tensorflow官方网站 tensorflow官方网站变为:https://tensorflow.google.cn/ 安装深度学习框架 0. ubuntu查看CUDA和cuDNN版本 C ...
- Java反射中Class.forName和classloader的区别
Java中Class.forName和classloader都可以用来对类进行加载. Class.forName除了将类的.class文件加载到jvm中之外,还会对类进行解释,执行类中的static块 ...
- VS Code Monokai Pro验证
最新的VS Code Monokai Pro激活方式 需要vscode,并且安装了monokai pro插件 进入目录 Mac OS cd -/.vscode/extensions/monokai.t ...