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. js 中加减乘除 比较精确的算法,js本身有些运算会出错,这里给出较精确的算法

    问题这样的: 37.5*5.5=206.08  (JS算出来是这样的一个结果,我四舍五入取两位小数) 我先怀疑是四舍五入的问题,就直接用JS算了一个结果为:206.08499999999998 怎么会 ...

  2. PB笔记之调用数据窗口时的过滤条件添加方式

    在PB查询数据窗口的数据时 通常可以有两种方式 一是在数据窗口事先写好查询条件,然后用retrieve()函数通过参数传递给数据窗口 这种方式适合查询条件较为简单,条件数较少的数据窗口 二是使用Set ...

  3. Istio技术与实践6:Istio如何为服务提供安全防护能力

    凡是产生连接关系,就必定带来安全问题,人类社会如此,服务网格世界,亦是如此. 今天,我们就来谈谈Istio第二主打功能---保护服务. 那么,便引出3个问题: l  Istio凭什么保护服务? l  ...

  4. my linux cmd

    常用的linux命令 一.vi yy 复制当前行 u 撤销 p 粘贴 dd 删除当前行 set nu 显示行号 gg 首行 G 末行 二.用户管理相关 useradd 添加用户   (默认创建一个与用 ...

  5. 监控SQL:通过SQL Server的DML触发器来监控哪些IP对表的数据进行了修改(2)

    原文:监控SQL:通过SQL Server的DML触发器来监控哪些IP对表的数据进行了修改(2) 在有些公司中,由于管理的不规范,或者是便于开发人员直接修改.部署程序,往往任何开发人员,都能登录到生产 ...

  6. Asp.Net进阶/管家模式+发布订阅模式:练习

    现在需要实现一个需求:我需要在一个窗体中发送一个信息,其余几个窗体都能同时接收到发送的消息. 1.界面:一个管家窗体,1个主窗体,2个订阅者窗体.其中管家窗体为启动窗体. 2.订阅:2个订阅窗体订阅主 ...

  7. vue基础部分

    一 vue概念 是一个构建用户界面的javascript框架 二 如何使用vue 1. 导入vue.js文件 2. 展示HTML 3. 建立vue对象,写JavaScript代码 vue的简单实用:申 ...

  8. 安装jQuery

    description jQuery,顾名思义,也就是JavaScript和Query(查询),即辅助JavaScript开发的库.jQuery是一个快速.简洁的JavaScript框架,是继Prot ...

  9. Lumen5.6使用JWT【最新教程】,亲身失败百次的总结

    一.前言 如果需要使用 Passport,可以参考在下之前的教程: 'Lumen5.4配置OAuth2.0[强迫症,就是要用最新版本的Lumen]' . 由于原作者文档的简洁性,同时 Lumen 下的 ...

  10. 修改Linux命令的别名:alias

    修改Linux命令的别名. (一)临时生效:仅限当前窗口 查看所有别名 alias 添加别名 alias ll='ls -lh' 重置别名 alias ll='ls -alh' 删除别名: unali ...