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 ...
随机推荐
- Mock常用占位符一览
1.随机字符串(类型 , 位数)@string(lower,10) lower : 小写字母upper : 大写字母number : 数字 2.随机int(下限 , 上限)@integer(60, 1 ...
- java 随机生成4位随机数
java 随机生成4位的随机数测试类 @org.junit.Testpublic void testRandom(){ String msg="您的注册码为%s,谢谢注册!"; S ...
- VS.NET(C#)--2.6_ASP.NET服务器控件层次结构
ASP.NET服务器控件层次结构 语法 <asp:ControlType Id="ControlID" Rubat="Server" Property=& ...
- 炫酷的可视化工具包——cufflinks
前言 学过Python数据分析的朋友都知道,在可视化的工具中,有很多优秀的三方库,比如matplotlib,seaborn,plotly,Boken,pyecharts等等.这些可视化库都有自己的特点 ...
- vue组件间的数据传递
父组件向子组件传递数据 在 Vue 中,可以使用 props 向子组件传递数据. App.vue HelloWorld.vue 在子组件部分: 如果需要从父组件获取 logo 的值,就需要使用 p ...
- node.js 微信开发1-接入
准备工作1 域名准备 无论是个人开发还是做公司项目域名都是必不可少的 前期我个人用过花生壳做个开发测试,挺好用的,就是现在要收费了,开通花生壳要收费,开通内网穿透要收费(为啥要内网穿透呢,因为微信接入 ...
- c# List<Object>和List<实体>相互转化
开发的过程中总会遇到各种转化的问题,现在我做的开发接口中就遇到需要将List<Object> 中的Object又含有List<实体>归为一个list中,就是要list中没有Li ...
- [nginx] nginx使用SNI功能的方法
SNI是什么 在使用TLS的时候,http server希望根据HTTP请求中HOST的不同,来决定使用不同的证书. SNI细节 由于HTTP的HOST字段在HTTP GET中.而TLS的握手以及证书 ...
- Linux下制作静态库 & 动态库
静态库 1.将.c生成.o文件 gcc-cadd.c-o add.o 2.使用ar工具制作静态库 ar rcs lib库名.a add.o sub.o div.o 3.编译静态库到可执行文件中 gcc ...
- JS基础篇【1】
该文讲解适用于有一定语言开发基础的朋友们,亦可当作久别重逢之回顾! 1.JS简介 JavaScript 是互联网上最流行的脚本语言,这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记 ...