题目链接:Codeforces Round 998 (Div. 3)

总结:复建,Cwa两发,E读假题了。

A. Fibonacciness

tag:签到

Solution:简单模拟一下即可。

void solve(){
int a[5];
for (int i = 0; i < 5; i ++){
if (i == 2){
continue;
}
cin >> a[i];
}
a[2] = a[0] + a[1];
int ans = 0;
for (int i = 2; i < 5; i ++){
if (a[i] == a[i - 1] + a[i - 2])
ans ++;
else
continue;
}
a[2] = a[3] - a[1];
int ans2 = 0;
for (int i = 2; i < 5; i ++){
if (a[i] == a[i - 1] + a[i - 2])
ans2 ++;
else
continue;
}
cout << max(ans, ans2) << endl;
}

B. Farmer John's Card Game

tag:签到

Solution:显然需要按顺序一个人一个人递增的出牌,将每个人的牌排序以后,模拟出牌顺序,看是否能够满足。

void solve(){
int n, m;
cin >> n >> m;
vector<pii> ans(n); //
set<int> a[n]; for (int i = 0; i < n; i ++){
ans[i].se = i; // 每个人的位置
for (int j = 0; j < m; j ++){
int x;
cin >> x;
a[i].insert(x);
}
ans[i].fi = *(a[i].begin()); // 每个人最小的牌
} sort(ans.begin(), ans.end());
int t = 0;
for (int j = 0; j < m; j ++)
for (int i = 0; i < n; i ++){
if (*(a[ans[i].se].begin()) == t){
a[ans[i].se].erase(t);
t ++;
}
else{
cout << -1 << endl;
return;
}
} for (int i = 0; i < n; i ++){
cout << ans[i].se + 1 << " \n"[i + 1 == n];
}
}

C. Game of Mathletes

tag:思维

Solution:得分是固定的,只要有两个数能够加起来等于K,那么b就能得分。

void solve(){
int n, k;
cin >> n >> k;
vector<int> a(n); multiset<int> st;
for (int i = 0; i < n; i ++){
cin >> a[i];
st.insert(a[i]);
}
sort(a.begin(), a.end()); int ans = 0;
for (int i = 0; i < n; i ++){
if (st.size() == 0 || a[i] >= k)
break;
int b = k - a[i];
if (st.find(a[i]) != st.end() && st.find(b) != st.end()){
auto x = st.find(a[i]);
st.erase(x);
if (st.find(b) == st.end()){ // 当a == b时,避免RE
st.insert(a[i]);
continue;
}
auto y = st.find(b);
st.erase(y);
ans ++;
}
} cout << ans << endl;
}

D. Subtract Min Sort

tag:思维

Description:给定n个数,可以进行任意次操作,每次操作令\(a_i\)和\(a_{i + 1}\)同时减去\(min(a_i, a_{i +1})\)。问能否将原序列变为非递减序列。

Solution:从第一个数开始模拟,显然第一个数比第二个数大不行,否则我们让它们进行操作,则第一个数变为零,向后继续操作即可。

void solve(){
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i ++){
cin >> a[i];
} for (int i = 1; i < n; i ++){
if (a[i - 1] > a[i]){
cout << "NO\n";
return;
}
a[i] -= a[i - 1];
} cout << "YES\n";
}

E. Graph Composition

tag:并查集

Description:给定两个无向图F和G,可以对F操作:

  • 在u,v之间建一条边。
  • 删除一条u,v之间的边。
  • 求最小操作次数,使得F中u,v之间有一条路径,当且仅当G中u,v之间有一条路径。

Solution:建两个并查集f和g,将g中的点进行合并,首先枚举F中的边,如果两点在g中不属于同一个并查集则将它们删除,否则在f中合并它们。然后枚举g中的边,如图两点在同一个并查集中,则在f中将它们合并,记录操作次数。

Competing:将图看成了连通图。

void solve(){
int n, m1, m2;
cin >> n >> m1 >> m2;
set<pii> a1, a2;
DSU f(n + 1), g(n + 1); for (int i = 0; i < m1; i ++){
int x, y;
cin >> x >> y;
if (x > y)
swap(x, y);
a1.insert({x, y});
} for (int i = 0; i < m2; i ++){
int x, y;
cin >> x >> y;
a2.insert({x, y});
g.merge(x, y);
} int ans = 0;
for (auto [x, y] : a1){
if (g.find(x) != g.find(y)){ // 必须删
ans ++;
}
else{
f.merge(x, y);
}
} for (auto [x, y] : a2){
if (g.find(x) == g.find(y)){
ans += f.merge(x, y);
}
}
cout << ans << endl; }

Codeforces Round 998 (Div. 3)的更多相关文章

  1. 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 ...

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

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

  3. Codeforces Round #368 (Div. 2)

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

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

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

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

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

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

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

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. 2023年10月,红米(小米)note 8 pro 优化记

    看了红米的note 13 pro和note 12 turbo的参数和价格后,我决定下单买个note8 pro的手机壳,确实有新手机的感觉了. 我note8 pro手机参数如下 MIUI 12.0.5 ...

  2. 给网站免费升级https协议

    给网站免费升级HTTPS协议,可以通过申请并部署免费的SSL证书来实现.以下是一个详细的步骤指南: 一.申请免费SSL证书 选择证书颁发机构: 可以选择像JoySSL这样的公益项目,它提供免费.自动化 ...

  3. 个人wiki

    1:记录自己的知识体系 2:轻量级wiki系统(排除XWiki) 3:开源 4:支持通用wiki语法(排除dokuwiki) 5:有好的编辑器(排除MediaWiki) 6:最好是java,或者php ...

  4. msde2000的关于无法访问lonle实例的master数据库恢复

    某次关机重启后,lonele数据库实例无法访问,查看发现相应的服务(MSSQL$LONELE2.SQLAgent$LONELE2)无法启动. --------------------------- 服 ...

  5. Servlet内存马

    emmm.....本篇写的还不是很完善,学着后边的忘着后边的,后续边学边完善吧........ 概述 如果你不了解IDEA调试Tomcat和Tomcat各组件概念可以参考我的博客:JAVA WEB环境 ...

  6. Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Faile

    解决方法: 1.新建一个安卓应用,复制下面路径红色框的代码  去替换  导入应用中的代码,就是修改gradle版本: 2.在导入的应用中如下路径添加信息 代码: android.overridePat ...

  7. Vue.js 事件绑定

    1.事件监听 v-on:eventName可以简写成@eventName 事件对象:在HTML中,事件参数为$event,但是即使不传递,在回调函数中也可以直接使用event读取 <div id ...

  8. 销讯通CRM系统如何管理医药代表的销售过程

    医药行业的销售代表与其他行业的销售代表在专业知识要求.客户群体.销售流程.以及行业特性等方面都存在明显的区别,他们必须具备更高的专业素养和综合能力. CRM(客户关系管理系统)在医药行业中对于管理医药 ...

  9. (一)Springboot + vue + 达梦数据库构建RBAC权限模型前后端分离脚手架保姆级教程(界面截图)

    用户登录  系统首页  用户列表  添加用户  修改用户  角色列表  添加角色  修改角色  

  10. 一图归纳三大种类矩阵范数:诱导范数,元素范数,Schatten范数,涵盖谱范数,2范数

    转载自:https://blog.csdn.net/qq_27261889/article/details/87902480