当前位置: 首页 > news >正文

Codeforces Round 888 (Div. 3)(视频讲解全部题目)

@[TOC](Codeforces Round 888 (Div. 3)(视频讲解全部题目))

Codeforces Round 888 (Div. 3)(A–G)全部题目详解
在这里插入图片描述

A Escalator Conversations

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;void solve()
{int n, m, k, H;cin >> n >> m >> k >> H;int ans = 0;for(int i = 0; i < n; i ++){int h;cin >> h;int dis = abs(h - H);if(h != H && dis % k == 0 && dis / k < m)ans ++;}cout << ans << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;cin >> t;while(t--)solve();
}

B Parity Sort

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;void solve()
{int n;cin >> n;vector<int>a(n);for(int i = 0; i < n; i ++)cin >> a[i];vector<int>b;b = a;sort(b.begin(), b.end());for(int i = 0; i < n; i ++){if(a[i] % 2 != b[i] % 2){cout << "NO" << endl;return;}}cout << "YES" << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;cin >> t;while(t--)solve();
}

C Tiles Comeback

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;void solve()
{int n, k;cin >> n >> k;vector<int>a(n);for(int i = 0; i < n; i ++)cin >> a[i];if(a[0] == a.back()){if(count(a.begin(), a.end(), a[0]) >= k)cout << "YES" << endl;elsecout << "NO" << endl;}else{int c1 = count(a.begin(), a.end(), a[0]);int c2 = count(a.begin(), a.end(), a.back());int cnt = 0;for(int i = 0; i < n; i ++){if(a[i] == a[0])cnt ++;if(a[i] == a.back())c2 --;if(cnt == k)break;}if(c1 >= k && c2 >= k){cout << "YES" << endl;}else{cout << "NO" << endl;}}
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;cin >> t;while(t--)solve();
}

D Prefix Permutation Sums

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;void solve()
{int n;cin >> n;vector<int>a(n - 1);for(int i = 0; i < n - 1; i ++)cin >> a[i];int sum = n * (n + 1) / 2;if(sum != a.back()){a.push_back(sum);map<int,bool>st;for(int i = 0; i < n; i ++){int b;if(!i)b = a[i];elseb = a[i] - a[i - 1];if(b <= 0 || b > n || st[b]){cout << "NO" << endl;return;}st[b] = true;}cout << "YES" << endl;}else{map<int,bool>st;int x, cnt = 0;for(int i = 0; i < n - 1; i ++){int b;if(!i)b = a[i];elseb = a[i] - a[i - 1];if(b <= 0 || b > 2 * n){cout << "NO" << endl;return;}if(b > n || st[b]){x = b;cnt ++;}st[b] = true;}if(cnt > 1){cout << "NO" << endl;return;}else{int sum = 0;int c = 0;for(int i = 1; i <= n; i ++){if(!st[i]){sum += i;c ++;}}if(c == 2 && sum == x){cout << "YES" << endl;}else{cout << "NO" << endl;}}}
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;cin >> t;while(t--)solve();
}

E Nastya and Potions

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5 + 10;
int c[N], idx[N], ans[N];
map<int,bool>p;
int n, k;
vector<int>edge[N];void bfs()
{queue<int>q;for(int i = 0; i < n; i ++){if(idx[i] == 0){q.push(i);if(p[i])ans[i] = 0;elseans[i] = c[i];}}while(q.size()){int t = q.front();q.pop();for(int i = 0; i < edge[t].size(); i ++){int son = edge[t][i];ans[son] += ans[t];idx[son] --;if(idx[son] == 0){if(p[son])ans[son] = 0;elseans[son] = min(ans[son], c[son]);q.push(son);}}}
}void solve()
{cin >> n >> k;for(int i = 0; i < n; i ++){c[i] = idx[i] = ans[i] = 0;edge[i].clear();}p.clear();for(int i = 0; i < n; i ++)cin >> c[i];for(int i = 0; i < k; i ++){int x;cin >> x;x --;p[x] = true;}for(int i = 0; i < n; i ++){int m;cin >> m;for(int j = 0; j < m; j ++){int x;cin >> x;x --;idx[i] ++;edge[x].push_back(i);}}bfs();for(int i = 0; i < n; i ++)cout << ans[i] << " ";cout << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;cin >> t;while(t--)solve();
}

F Lisa and the Martians

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;void solve()
{int n, k;cin >> n >> k;vector<pii>a(n);for(int i = 0; i < n; i ++){cin >> a[i].first;a[i].second = i + 1;}sort(a.begin(), a.end());int minv = INT_MAX, a1, a2, p1, p2;for(int i = 0; i < n - 1; i ++){if(minv > (a[i].first ^ a[i + 1].first)){a1 = a[i].first, a2 = a[i + 1].first;p1 = a[i].second, p2 = a[i + 1].second;minv = a1 ^ a2;}}int x = 0;for(int i = 0; i < k; i ++){int x1 = (a1 >> i) & 1, x2 = (a2 >> i) & 1;if(x1 + x2 == 0)x += 1 << i;}cout << p1 << " " << p2 << " " << x << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;cin >> t;while(t--)solve();
}

G Vlad and the Mountains

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5 + 10;
int h[N], p[N];
struct NODE
{int a, b, w;
};
struct QRY
{int a, b, h_max, ii;
};
vector<NODE>edge;
vector<QRY>Q;
bool cmp1(NODE x, NODE y)
{return x.w < y.w;
}
bool cmp2(QRY x, QRY y)
{return x.h_max < y.h_max;
}int find(int x)
{if(x != p[x])p[x] = find(p[x]);return p[x];
}
void solve()
{edge.clear();Q.clear();int n, m;cin >> n >> m;for(int i = 1; i <= n; i ++)cin >> h[i];for(int i = 0; i < m; i ++){int a, b;cin >> a >> b;edge.push_back({a,b, max(h[a], h[b])});}sort(edge.begin(), edge.end(), cmp1);int q;cin >> q;vector<bool>ans(q);for(int i = 0; i <= n; i ++)p[i] = i;for(int i = 0; i < q; i ++){int a, b, e;cin >> a >> b >> e;Q.push_back({a, b, h[a] + e, i});}sort(Q.begin(), Q.end(), cmp2);int cnt = 0;for(int i = 0; i < q; i ++){while(cnt < m && Q[i].h_max >= edge[cnt].w){int pa = find(edge[cnt].a), pb = find(edge[cnt].b);if(pa != pb)p[pa] = pb;cnt ++;}if(find(Q[i].a) == find(Q[i].b))ans[Q[i].ii] = true;elseans[Q[i].ii] = false;}for(int i = 0; i < q; i ++){if(ans[i])cout << "YES" << endl;elsecout << "NO" << endl;}cout << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;cin >> t;while(t--)solve();
}
http://www.lryc.cn/news/99715.html

相关文章:

  • MySQL之深入InnoDB存储引擎——物理文件
  • Jquery操作html常用函数
  • 【Lua学习笔记】Lua进阶——Table,迭代器
  • 重庆市北斗新型智慧城市政府项目
  • FANUC机器人SRVO-217故障报警原因分析及参考解决办法
  • 统信UOS安装mysql数据库(mariadb)-统信UOS安装JDK-统信UOS安装nginx(附安装包)
  • 上门小程序开发|上门服务小程序|上门家政小程序开发
  • 1000道网络安全必备面试题合集,秋招金九银十必看!!!
  • 从0-1实现简易Raft分布式共识算法
  • Spring 创建和使用
  • Javadoc comment自动生成
  • vue3 +ts 报错 index.vue 不是模块
  • win10 hadoop报错 unable to load native-hadoop library
  • 前端(九)——探索微信小程序、Vue、React和Uniapp生命周期
  • MyBatis查询数据库(2)
  • Jenkins构建完成后发送消息至钉钉
  • 从浏览器输入url到页面加载(六)前端必须了解的路由器和光纤小知识
  • C语言假期作业 DAY 06
  • [nlp] tokenizer加速:fast_tokenizer=True
  • 基于OpenCV solvePnP函数估计头部姿势
  • STC12C5A系列单片机内部 EEPROM 的应用
  • 搭建测试平台开发(一):Django基本配置与项目创建
  • JavaWeb教程笔记
  • 数据库压力测试方法小结
  • Spring Boot——Spring Boot自动配置原理
  • 深度学习:Pytorch最全面学习率调整策略lr_scheduler
  • 【uniapp】更改富文本编辑器图片大小
  • 数据结构和算法一(空间复杂度、时间复杂度等算法入门)
  • Pytorch深度学习-----神经网络的基本骨架-nn.Module的使用
  • QT开发快捷键