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的更多相关文章

  1. Educational Codeforces Round 68 E. Count The Rectangles

    Educational Codeforces Round 68 E. Count The Rectangles 传送门 题意: 给出不超过\(n,n\leq 5000\)条直线,问共形成多少个矩形. ...

  2. Educational Codeforces Round 68 差G

    Educational Codeforces Round 68 E 题意:有 n 个线段,每个都是平行 x 或者 y 轴,只有互相垂直的两线段才会相交.问形成了多少个矩形. \(n \le 5000, ...

  3. Educational Codeforces Round 68 Editorial

    题目链接:http://codeforces.com/contest/1194                                            A.Remove a Progre ...

  4. Educational Codeforces Round 68 (Rated for Div. 2)---B

    http://codeforces.com/contest/1194/problem/B /* */ # include <bits/stdc++.h> using namespace s ...

  5. Educational Codeforces Round 68 (Rated for Div. 2)补题

    A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. leetcode动态规划笔记三---单序列型

    单序列型DP 相比一维DP,这种类型状态转移与过去每个阶段的状态都有关. Longest Increasing Subsequence : 求最大最小值 Perfect Squares : 求某个规模 ...

  2. 安装Nginx报错“Cannot retrieve metalink for repository: epel. Please verify its path and try again”

    CentOS 6.5中通过yum安装nginx报错. 搜了一下,很多都是修改某个配置文件的.但是在StackOverFlow的某个问题下,有人回答说修改配置文件并不是一个好的方法,虽然我采用了这个人的 ...

  3. Golang高阶:Golang1.5到Golang1.12包管理

    Golang1.5到Golang1.12包管理 1. 前言 Golang 是一门到如今有十年的静态高级语言了,2009年的时候算是正式推出了,然后到最近的一两年,2017-2018年的时候,突然直线上 ...

  4. jenkins pipeline中获取shell命令的标准输出或者状态

    //获取标准输出//第一种 result = sh returnStdout: true ,script: "<shell command>" result = res ...

  5. physdiskwrite 的简单使用

    physdiskwrite 的简单使用 参考  https://m0n0.ch/wall/physdiskwrite.php 来源 https://www.cnblogs.com/EasonJim/p ...

  6. 查询并批量插入数据的Sql命令

    INSERT INTO student(id,xuesheng,yuwen,shuxue,yingyu) SELECT id,xuesheng,yuwen,shuxue,yingyu FROM stu ...

  7. [技术翻译]预加载响应式图像,从Chrome 73开始实现

    本次预计翻译三篇文章如下: 01.[译]9个可以让你在2020年成为前端专家的项目 02.[译]预加载响应式图像,从Chrome 73开始实现 03.[译]您应该知道的13个有用的JavaScript ...

  8. 使用SAP Leonardo上的机器学习服务提取图片的特征向量

    要想提取图片的特征向量,首先得知道特征向量是什么. 我们假设这样一个服务场景,技师上门维修某设备,发现上面某零件损坏了,假设这位技师由于种种原因,没能根据自己的经验识别出这个零件的型号.此时技师掏出自 ...

  9. 前端HTML基础和head部分

    一.SOCKET服务器与浏览器交互 CS模式 -->  BS模式 CS模式逐渐向BS模式转移,底层都是socket客户端 浏览器给服务器发送请求 --> 服务器收到请求 --> 服务 ...

  10. Flutter——TextField组件(文本框组件)

    TextField组件的常用属性: 属性 描述 maxLines 设置此参数可以把文本框改为多行文本框 onChanged 文本框改变的时候触发的事件 decoration hintText 类似 h ...