比赛链接:https://codeforces.com/contest/1492

1492A.Three swimmers

题意:

有三名游泳的人,他们分别需要 \(a,b,c\) 分钟才能在一个游泳池游一个来回,第一个游泳者将在开始时间 \(0,a,2a,3a,…\) 分钟后在游泳池的左侧,第二个游泳者将在 \(0,b,2b,3b,…\) 分钟后,第三个将在 \(0,c,2c,3c,…\) 分钟后出现在池的左侧。

\(p\)​ 分钟后最少需要等待多长时间会有一个游泳者到达游泳池左侧。

思路:

签到题,

可以暴力遍历 \(a,b,c\) 寻找最小值,

也可以直接找 \(a,b,c\) 的倍数离 \(p\)​​ 差多少

注意开 long long....

【AC Code】

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _; for (cin >> _; _--;) {
ll p, a, b, c;
cin >> p >> a >> b >> c;
if (p % a == 0 || p % b == 0 || p % c == 0)
cout << "0\n";
else cout << min(a - p % a, min(b - p % b, c - p % c)) << "\n";
}
}

1492B. Card Deck

题意:

有 \(n\) 张卡,每张卡的值 \(1\sim n\),等于 \(p_i\),\(p_1\) 代表底卡,\(p_n\) 是顶卡,在每个步骤中,选择一些 \(k > 0\) 的整数,从原始卡片组中取出前 \(k\) 张卡片,然后按它们现在的顺序将它们放置在新卡片组的顶部。让阶数最大。

思路:

找最大的数输出最大的数加后边的所有数,接着找第二个······注意不要重复输出

【AC Code】

const int N = 1e5 + 10;
ll a[N], pos[N];
bool st[N];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _; for (cin >> _; _--;) {
vector<int>A;
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pos[i] = i;
st[a[i]] = 0;
}
ll t = n;
for (ll i = n; i >= 1; i -= 1) {
if (a[i] == t)
for (ll j = i; !st[a[j]] && j <= n; j += 1) {
st[a[j]] = 1;
A.emplace_back(a[j]);
}
while (st[t] && t >= 1) t -= 1;
}
for (ll i = 0; i < n; i += 1) cout << A[i] << " \n"[i == n - 1];
}
}

1492C. Maximum width

题意:

给你两个字符串 \(s,t\) 找 \(s\) 串和 \(t\) 串匹配的下标,然后找相邻下标之间的最大值,管你懂不懂看样例就完事了

思路:

看了半天样例发现只需要前后扫一遍,分别用两个数组去存前后扫的下标结果,取两个数组相邻位置的最大值

【AC Code】

const int N = 2e5 + 10;
int n, m, a[N], b[N];
string s, t;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
cin >> n >> m >> s >> t;
int i = 0, j = 0;
while (j < m) {
if (s[i] == t[j]) {
a[j] = i + 1;
i ++; j ++;
} else i ++;
}
i = n - 1, j = m - 1;
while (j > 0) {
if (s[i] == t[j]) {
b[j] = i + 1;
i --; j --;
} else i --;
}
int ans = 0;
for (int q = 0; q < m; q ++)
ans = max(ans, b[q + 1] - a[q]);
cout << ans << "\n";
}

1492D. Genius’s Gambit

题意:

给你三个数,\(a\) 代表 \(0\) 的个数,\(b\) 代表 \(1\) 的个数,\(k\) 代表 \(x-y\) 中 \(1\) 的个数,让你求出 \(x,y\) 满足 \(a,b,k\) 三个条件,如果没有输出 NO

思路:

构造题,说实话赛时没构造出来,这里参考了一下题解

由题目可知 \(x>y\) 是肯定的,所以我们不妨假设 \(x,y为11…00…\) ,然后对 \(y\) 进行变换,我们发现 \(y\) 最右边的1往后移动一位 \(x-y\) 的值就多一个 \(1\) ,最大为 \(a\)​ ,然后移动倒数第二个 \(1\) ,发现只能移动一次,如果移动两次不会多一个 \(1\)​ 。

假设

x 1110000

y 1110000

当 \(y\) 的倒数第一个 \(1\) 往右移动时发现 \(x-y\) 中 \(1\) 的个数 \(+1\) ,当y 1100001时 \(x-y\) 中 \(1\) 的个数为 \(4\) ,然后移动倒数第二个 \(1\),移动一次,发现 \(x-y\) 中 \(1\) 的个数变成了 \(5\) ,再移动一次发现又变回 \(4\) ,所以除了倒数第一个 \(1\) 可以移动多次,第一个 \(1\) 不能移动中间的 \(1\) 只能移动一次,我们可以找出规律,最大的值为 \(a+b-2\)​​​ 。

【AC Code】

int a, b, k;

int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> a >> b >> k;
if (k == 0) {
cout << "Yes" << '\n';
string x = "", y = "";
x += '1';
b--;
for (int i = 0; i < a; i++) x += '0';
for (int i = 0; i < b; i++) x += '1';
cout << x << '\n';
cout << x << '\n';
return 0;
}
k--;
if (a > 0 && b >= 2 && (a + b - 3 >= k)) {
cout << "Yes" << '\n';
string x = "";
string y = "";
a--; b -= 2;
x += '1'; y += '1'; x += '1'; y += '0';
for (int i = 0; i < k; i++) {
if (a) {
a--;
x += '0'; y += '0';
} else {
b--;
x += '1'; y += '1';
}
}
x += '0'; y += '1';
while (a--) {
x += '0'; y += '0';
}
while (b--) {
x += '1'; y += '1';
} cout << x << '\n';
cout << y << '\n';
} else
cout << "No" << '\n';
}

模拟构造,我不会(QAQ

1492E. Almost Fault-Tolerant Database

题意:

给定 \(n\) 个长度为 \(m\) 的数组,需要输出一个长度为 \(m\) 的数组,使得这些数组之间不同的数不超过两个,输出YES,输出你构造的数组,若有多种情况,可任意输出一种。如若不存在,输出NO。

思路:

假设第一个数组为标准数组,遍历

  1. 不同数小于等于 \(2\),没问题
  2. 不同数大于 \(4\) ,直接输出NO
  3. 就是 \(3,4\) 的情况,我们找差异数最大的那个也就是 \(4\) 的情况,枚举修改的两个位置,判断是否可以成立。

【AC Code】

const int N = 250010;
int n, m;
vector <int> s[N];
bool check2(vector<int> &v) {
for (int i = 1; i < n; i ++) {
int cnt = 0;
for (int j = 0; j < m; j ++)
if (s[i][j] != v[j]) cnt ++; if (cnt > 3) return false;
else if (cnt == 3) {
int ans = 1;
for (int j = 0; j < m; j ++) {
if (s[i][j] != v[j] && v[j] == -1) {
ans = 0;
v[j] = s[i][j];
break;
}
}
if (ans) return false;
}
}
return true;
} bool check() {
int cnt = 0, ax = 0, id;
for (int i = 1; i < n; i ++) {
int ans = 0;
for (int j = 0; j < m; j ++)
if (s[i][j] != s[0][j]) ans ++; if (ans > 4) return false;
if (ans <= 2) cnt ++;
if (ans > ax)ax = ans, id = i;
} if (cnt == n - 1) {
cout << "Yes\n";
for (int i = 0; i < m; ++i) cout << s[0][i] << " \n"[i == m - 1];
return true;
} vector<int> a;
for (int i = 0; i < m; i ++)
if (s[0][i] != s[id][i]) a.push_back(i); for (int i = 0; i < a.size(); i ++) {
for (int j = 0; j < a.size(); j ++) {
if (i == j) continue; vector<int> b = s[0]; b[a[i]] = s[id][a[i]];
b[a[j]] = -1; if (check2(b)) {
cout << "Yes\n";
for (int i = 0; i < m; ++i) cout << (b[i] == -1 ? s[0][i] : b[i]) << " \n"[i == m - 1];
return true;
}
}
}
return false;
} int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i ++) {
for (int j = 0, x; j < m; j ++) {
cin >> x;
s[i].push_back(x);
}
}
if (!check()) puts("No");
}

Codeforces Round #704 (Div. 2) A~E的更多相关文章

  1. Codeforces Round #704 (Div. 2), problem: (C) Maximum width还是要多学习

    Problem - C - Codeforces 看清题目要求, 最重要部分在第二段. 大佬最后给出的代码果然简单, 思路简单化, 未必非要把答案在一个大括号里全部完成, 两个指针同时跑,中间加了一堆 ...

  2. Codeforces Round #704 (Div. 2)

    A. Three swimmers 题意:第一个人跳水是每隔a分钟去一次,第二个人跳水是每隔b分钟,第三个人跳水是每隔c分钟,一个人准备在p分钟的 时候去跳水,问需要最少等待多长时间才能轮到前三个人 ...

  3. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  4. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  5. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  6. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  7. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  8. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  9. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  10. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. SpringBoot获取启动类Application所在包路径

    1. @SpringBootApplication 注解中引用了@EnableAutoConfiguration 注解. 2.查看 @EnableAutoConfiguration 注解,发现引用了  ...

  2. [ARC156C] Tree and LCS

    Problem Statement We have a tree $T$ with vertices numbered $1$ to $N$. The $i$-th edge of $T$ conne ...

  3. CISC与RISC

  4. Excel对比两张表的某一列,匹配上则进行数据copy

    VLOOKUP(参数1,参数2,参数3,参数4) 参数1: 查找值 参数2:指定查找数据源的范围 参数3:返回查找区域的第几列数据 参数4:精确查找输入参数"0"or"f ...

  5. RV1126 分区教程

    一.前言 期初我是想弄一个分区存放自己的 APP 程序,如果需要更改应用的时候,只需要烧写独立的分区即可,就不需要重新烧写 rootfs.这是一个简单的操作,为啥还需要记录了,因为我在里面遇到了一些坑 ...

  6. django分页器使用

    https://docs.djangoproject.com/en/3.2/topics/pagination/ Django 提供了高级和低级方法来帮助您管理分页数据--即,分成多个页面的数据,并带 ...

  7. NC65主键含义

    最简单的办法,调用用友的类 import nc.jdbc.framework.generator.SequenceGenerator; IdGenerator idGenerator = new Se ...

  8. 技巧:在Excel或Word中将回车替换掉

    一.在Excel中替换 将回车替换为逗号或其他字符,如下面的屏幕截图所示. 1. 在 查找和替换 对话框中 查找内容 字段,请按 Ctrl + J 键,然后在 更换 字段中,键入所需的字符,在这种情况 ...

  9. Redis 使用的 10 个小技巧

    Redis 在当前的技术社区里是非常热门的.从来自 Antirez 一个小小的个人项目到成为内存数据存储行业的标准,Redis已经走过了很长的一段路. 随之而来的一系列最佳实践,使得大多数人可以正确地 ...

  10. DVWA Cross Site Scripting (XSS) 跨站脚本攻击

    文章目录 DVWA_XSS(Stored) 存储性XSS 1.Low 2.Medium 3.High 4.Impossible XSS平台 DVWA_XSS(Stored) 存储性XSS 一句话概括: ...