写在前边

链接:Codeforces Global Round 13

\(A,B,C,D\)

A. K-th Largest Value

链接:A题链接

题目大意:

有一个字串只由\(0、1\)组成,有两个操作,\(1\)是让其中\(a_x\)变为\(1-a_x\),\(2\)是询问数组中第\(k\)大的数。

思路

很简单了,字串中元素只在\(0、1\)中变化,要问第\(k\)大的数字,那么非\(1\)即\(0\),就用一个\(map\)维护\(0,1\)的数量就好了

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 10000007; const int N = 1E5 + 10;
int a[N]; void solve() {
int n, q;
scanf("%d%d", &n, &q);
map<int, int> cnt;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
}
while (q--) {
int t, x;
scanf("%d%d", &t, &x);
if (t == 1) {
if (a[x] == 1) {
a[x] = 0;
cnt[0]++, cnt[1]--;
} else {
a[x] = 1;
cnt[1]++, cnt[0]--;
}
} else if (t == 2) {
if (cnt[1] >= x) puts("1");
else puts("0");
}
}
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}

B. Minimal Cost

链接:B题链接

题目大意:

每行一个箱子,第\(i\)行箱子的坐标为\(a_i\),你的任务就是推箱子,然后把利用最小的花费把开一条路使得你可以从左上角走到右下角。

思路

注意

  1. 每行就一个!
  2. 你可以随便方向的走!

    那么这样就很简单了,只需要在一列箱子中开一个口就好了,然后不断更新答案即可。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 10000007; const int N = 110;
int a[N]; void solve() {
int n, u, v;
scanf("%d%d%d", &n, &u, &v);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int res = 2e9 + 10;
for (int i = 2; i <= n; i++) {
if (abs(a[i] - a[i - 1]) > 1) res = 0;
if (a[i] == a[i - 1]) res = min(res, v + min(v, u));
if (abs(a[i] - a[i - 1]) == 1) res = min(res, min(v, u));
} printf("%d\n", res);
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
} return 0;
}

C. Pekora and Trampoline

链接:C题链接

题目大意:

跳床,有\(n\)个跳床,床的高度为\(s_i\),每在上边跳一次那么\(s_i\)减小\(1\),每次跨越着跳,当前在\(i\)那么一步会跳到\(i + s_i\)去,每次可以从任意一个跳床开始跳,直到跳出所有跳床算一次操作,那么经过多少次操作,所有的\(s_i\)都变为\(1\),注意已经变为\(1\)的床不会再减小。

思路

贪心的想,假如我们要是所有的床都变为\(1\),那么我们每次一定得从最左边跳到最右边,所以不如直接贪心加模拟的方法解题。

1.维护一个\(p\)数组,\(p_i\)表示已经在第\(i\)张床上跳了\(p_i\)次。

2.更新答案\(res += max(0, s[i] - p[i] - 1)\),即如果\(s[i] - 1 > p[i]\)说明还需要在第i张床上跳\(s[i] - p[i] - 1\)次,如果\(s[i] - 1 \leq p[i]\),那么说明第\(i\)张床上\(s[i]\)已经变为\(1\)。同时如果在第i张床上跳,因为\(s[i]\)每次减一,直到减法为\(1\)(\(s[i] = 1\)就没必要跳了),那么会影响后边第\(i + s[i], ...,i + 2\)床。

3. 还有就是,如果第\(i\)张床上跳的过多,即\(s[i]\)已经变为\(1\)了,那么第\(i\)张床上多余的跳跃次数可以转移到下一张床上。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 10000007; LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
} const int N = 5010;
int s[N];
int p[N]; void solve() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &s[i]); LL res = 0;
memset(p, 0, sizeof p);
for (int i = 1; i <= n; i++) {
int x = max(0, s[i] - p[i] - 1);
res += x;
for (int j = i + 2; j <= min(n, i + s[i]); j++) {
p[j]++;
}
p[i + 1] += max(p[i] - s[i] + 1, 0);
}
printf("%lld\n", res);
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}

D. Zookeeper and The Infinite Zoo

链接:D题链接

题目大意:

可以在结点\(u\)到\(u+v\)连一条边,当前仅当\(u \, \& \, v = v\)的时候,然后给定\(q\)个询问,每次两个端点\(u_i\), \(v_i\)问是否能从\(u_i\)到\(v_i\)。

思路

首先发现两个性质:

  1. 假如现结点为\(v\),那么它一定可以转移到\(2 * v\),很显然。
  2. 还有就是要满足\(u \, \& \, v = v\),那么起码满足\(u \leq v\),否则直接\(pass\)掉即可

然后再推到发现,\(u\)中\(1\)的个数必须要大于等于\(v\)中\(1\)的个数,为什么呢?

我们令\(k = v - u\).

我们发现,因为\(u \, \& \, k = k\),那么说明,\(u\)与\(k\)的二进制数中存在\(1\)的位数一定在同一位啊,否则不可能按位与得到\(k\),然后实现\(u\)转移到\(u+k = v\),那么\(v\)相对于\(u\)来说肯定是\(u\)其中的某些\(1\)进位才得到了\(u+k = v\),那么所以说\(v\)中\(1\)得个数肯定是小于等于\(u\)中\(1\)得个数的,举两个例子:

\(u_(2) = 011\), \(k_(2) = 001\),那么\(v_(2) = 100\)。\(1\)的个数减少了。

\(u_(2) = 011\), \(k_(2) = 011\),那么\(v_(2) = 110\)。\(1\)的个数不变。

那么单纯满足这个条件就对了吗,当然不是。

还要满足,\(v\)中的每一位\(1\)要高于\(u\)中每一位的\(1\),总不能越转移越低吧。那么满足这两个条件,\(u\)到\(v\)就可以进行转移了,那么上边的操作都可以用\(lowbit\)运算就可以了

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> //#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline") using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int Mod = 10000007; int lowbit(int x) {
return x & (-x);
} void solve() {
int u, v;
scanf("%d%d", &u, &v); if (u > v) {
puts("NO");
return;
}
int uu = u, vv = v;
int cnt1 = 0, cnt2 = 0;
while (uu) { //u中1的个数
uu -= lowbit(uu);
cnt1++;
}
while (vv) { //v中1的个数
vv -= lowbit(vv);
cnt2++;
}
while (u && v) { //必须往高位推才行
if (lowbit(u) > lowbit(v)) {
puts("NO");
return;
}
u -= lowbit(u), v -= lowbit(v);
}
if (cnt1 >= cnt2) puts("YES");
else puts("NO");
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
} return 0;
}

Codeforces Global Round 13 A-D题题解的更多相关文章

  1. Codeforces Global Round 13

    比赛地址 A(水题) 题目链接 题目: 给出一个\(01\)序列,有2种操作:1.将某个位置取反:2.询问\(01\)序列中第\(k\)大的数 解析: 显然维护1的数目即可 #include<b ...

  2. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  3. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  4. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  5. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  6. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  7. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  8. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  9. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  10. Codeforces Global Round 17

    Codeforces Global Round 17 A. Anti Light's Cell Guessing 坑点:\(n=1,m=1\) 时答案为 \(0\) . 其他情况:当 \(n=1\) ...

随机推荐

  1. Linux下定时清空某个文件

    问题 在一台单点机器部署完成且运行一段时间后,发现页面接口报错,登上机器发现磁盘满了.通过du -lh --max-depth=1 和 du -sh * 找出是哪个文件. 发现是 项目中 stdout ...

  2. Java的readBytes是怎么实现的?

    1.前言 众所周知,Java是一门跨平台语言,针对不同的操作系统有不同的实现.本文从一个非常简单的api调用来看看Java具体是怎么做的. 2.源码分析 从FileInputStream.java中看 ...

  3. Ubuntu新建Django工程错误:ModuleNotFoundError: No module named 'distutils.core'

    ubuntu18.04 默认没有安装 pip ,需要安装 python3-pip,即可解决 1 sudo apt-get install python3-pip 在shell脚本中输入以下命令: 1 ...

  4. 让nodejs开启服务更简单--express篇

    上一篇文章说到,nodejs获取客户端请求需要我们自己去处理请求参数.请求方式等,而在express框架内部集成了很多好用的方法,我们不需要从0开始编写各种处理逻辑,这样可以极大提高我们的开发效率~ ...

  5. html5 2.0学习

    列表定义:是一种特别的对象集合.集合:集中在一起合二为一(聚集). 聚集:多个列(信息资源)排在一起.信息资源:一堆数据,可能是字符,可能是图片. 列表分类:有序列表 无序列表  (自)定义列表  有 ...

  6. python将print的打印内容保存到日志

    将python程序中的所有打印内容都输出到日志文件中,在程序执行完成后,方便查询程序运行过程是否出现异常. 1. 将打印内容输出到日志文件 1.1 代码实现: sys.stdout = open('s ...

  7. 知识图谱(Knowledge Graph)根本概念

    目录 知识图谱 定义 基础概念: 知识图谱构建的关键技术 知识图谱的构建 实体命名识别 知识抽取 实体统一 指代消解 知识图谱的存储 RDF和图数据库的主要特点区别 知识图谱能干什么 反欺诈 不一致性 ...

  8. Pytest+Jenkins 学习笔记

    Pytest+Jenkins 学习笔记 在软件测试工作中,单元测试通常是由开发人员执行的.针对最小单元粒度的组件测试,在完成了单元粒度的测试任务之后,通常就需要交由专职的测试人员将这些单元级的组件放到 ...

  9. nvm、node、vue安装、vue项目创建打包

    nvm.node.vue安装.创建vue项目 nvm作用:可以管理多个版本的node,切换node版本,下载node. 前情提要 参 考:https://zhuanlan.zhihu.com/p/51 ...

  10. Solution -「洛谷 P5046」「YunoOI 2019 模拟赛」Yuno loves sqrt technology I

    Description Link. 无修改区间求逆序对. Solution 首先有一个显然的 \(\Theta(N\sqrt{N}\log_{2}N)\) 做法,由于过不了所以我就不废话. 其实有了 ...