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

Codeforces Round 871 (Div. 4)(A~H)

目录

比赛链接

A. Love Story

B. Blank Space

C. Mr. Perfectly Fine

D. Gold Rush

E. The Lakes

F. Forever Winter

G. Hits Different

H. Don't Blame Me


比赛链接

Dashboard - Codeforces Round 871 (Div. 4) - Codeforces

A. Love Story

找到与codeforces 有多少个不同的字符。

#include<bits/stdc++.h>
#define int long long  
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;
string s = "codeforces";
void solve() {string st;cin >> st;int ans = 0;for (int i = 0; i < st.size(); i++){if (st[i] != s[i])ans++;}cout << ans << "\n";}
signed main() {ios;TESTsolve();return 0;
}

B. Blank Space

找连续最长的0.

#include<bits/stdc++.h>
#define int long long  
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;void solve() {int n;cin >> n;int cnt = 0, ans = 0;for (int i = 1; i <= n; i++){int x;cin >> x;if (x == 0) cnt++;else{ans = max(ans, cnt);cnt = 0;}}ans = max(ans, cnt);cout << ans << "\n";
}
signed main() {ios;TESTsolve();return 0;
}

C. Mr. Perfectly Fine

分成01、10、11的三种情况,找全部的最小值,前面两个的最小值相加与第三个的最小值比较出最小值。

#include<bits/stdc++.h>
#define int long long  
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;void solve() {int n;cin >> n;int c1 = 1e9, c2 = 1e9, c3 = 1e9;for (int i = 1; i <= n; i++){int t;cin >> t;string s;cin >> s;if (s == "01") c2 = min(c2, t);if (s == "10") c1 = min(c1, t);if (s == "11") c3 = min(c3, t);}int res = min(c1 + c2, c3);if (res != 1e9)cout << min(c1 + c2, c3) << "\n";else cout << "-1\n";
}
signed main() {ios;TESTsolve();return 0;
}

D. Gold Rush

按照题意可以将一堆分成三堆,看看目标是否出现即可,搜索。

#include<bits/stdc++.h>
#define int long long  
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;void solve() {int n, m;cin >> n >> m;if (m > n){cout << "NO\n";return;}if (n == m){cout << "YES\n";return;}queue<int>q;q.push(n);while (q.size()){int k = q.front();q.pop();if (k == m){cout << "YES\n";return;}if (k < m|| k % 3 != 0) continue;int t=k / 3;q.push(t);q.push(t * 2);}cout << "NO\n";
}signed main() {ios;TESTsolve();return 0;
}

E. The Lakes

dfs染色法。

#include<bits/stdc++.h>
#define int long long  
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;
int vis[1001][1001];
int a[1001][1001];
int q[N];
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
int n, m;
int sum = 0;
int ans = 0;
void dfs(int x, int y, int tag)
{vis[x][y] = tag;sum += a[x][y];ans = max(ans, sum);for (int i = 0; i < 4; i++){int tx = x + dx[i];int ty = y + dy[i];if (tx<1 || ty<1 || tx>n || ty>m) continue;if (a[tx][ty] == 0) continue;if (vis[tx][ty]) continue;dfs(tx, ty, tag);}
}
void solve() {cin >> n >> m;ans = 0;for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++){cin >> a[i][j];}}int cnt = 0;for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++){if (a[i][j] == 0) continue;if (vis[i][j]) continue;sum = 0;++cnt;dfs(i, j, cnt);}}cout << ans << "\n";for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++){vis[i][j] = 0;}}
}signed main() {ios;TESTsolve();return 0;
}

F. Forever Winter

模拟一下,与出入度为1的点连接的就是与主节点连接的点,输出他们的出入度即可,与主节点连接的点,出入度需要减一。

#include<bits/stdc++.h>
#define int long long  
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;
void solve() {int n, m;cin >> n >> m;vector<vector<int>>f(n + 1);for (int i = 1; i <= m; i++){int u, v;cin >> u >> v;f[u].push_back(v);f[v].push_back(u);}set<int>q;for (int i = 1; i <= n; i++){if (f[i].size() == 1){q.insert(f[i][0]);}}int ans1;for (auto x : q){ans1 = f[x].size() - 1;break;}int ans2;for (int i = 1; i <= n; i++){set<int>tt;for (auto x : f[i]) tt.insert(x);if (tt == q){ans2 = f[i].size();break;}}cout << ans2 << ' ' << ans1 << "\n";
}signed main() {ios;TESTsolve();return 0;
}

G. Hits Different

一开始用搜索,优化半天还是超时,正解是二位数组前缀和dp。

#include<bits/stdc++.h>
#define int long long  
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;
int a[1500][1500];
int cnt=1;
int ans[N];
void solve() {int n;cin >> n;cout << ans[n] << "\n";
}signed main() {for (int i = 1; i < 1500; i++){for (int j = i - 1; j >= 1; j--){a[j][i - j] = a[j - 1][i - j] + a[j][i - j - 1] - a[j - 1][i - j - 1] + cnt * cnt;ans[cnt] = a[j][i - j];cnt++;}}ios;TESTsolve();return 0;
}

H. Don't Blame Me

找子序列所有元素的与和的二进制里1的个数等于k,数位dp。

#include<bits/stdc++.h>
#define int long long  
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;
int dp[N][64];
int a[N];
void solve()
{int n, k;cin >> n >> k;for (int i = 1; i <= n; i++){cin >> a[i];}for (int i = 1; i <= n; i++){dp[i][a[i]] = 1;for (int j = 0; j <= 63; j++){dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;dp[i][j & a[i]] = (dp[i][j & a[i]] + dp[i - 1][j]) % mod;}}int ans = 0;for (int i = 0; i <= 63; i++){int cnt = 0;for (int j = 0; j < 6; j++){if ((i >> j) & 1){cnt++;}}if (cnt == k){ans = (ans + dp[n][i]) % mod;}}cout << ans << "\n";for (int i = 1; i <= n; i++){for (int j = 0; j <= 63; j++){dp[i][j] = 0;}}
}
signed main() {ios;TESTsolve();return 0;
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 家里浮毛粉尘到处飞?宠物空气净化器出动帮你解决
  • 搜索 ---- 练习题(洛谷)
  • 05:【stm32】重映射AFIO
  • VIVADO IP核之DDS直接数字频率合成器使用详解
  • c#怎么折叠代码快捷
  • el-form-item,label在上方显示,输入框在下方展示
  • Bug太多,苹果手机升级到18.1后怎么降级
  • 状态模式-系统架构师(四十二)
  • 飞天发布时刻:大数据AI平台产品升级发布
  • Webpack入门基础知识及案例
  • 短视频SDK,支持Flutter跨平台框架,加速产品上线进程
  • 3D展示的前景如何?
  • 线程与多线程(二)
  • 中秋节喝酱酒的习俗是什么时候开始的?
  • 【07】JVM是怎么实现invokedynamic的
  • CentOS7简单部署NFS
  • EOS是什么
  • JavaScript设计模式之工厂模式
  • LeetCode算法系列_0891_子序列宽度之和
  • Linux后台研发超实用命令总结
  • Linux中的硬链接与软链接
  • Node + FFmpeg 实现Canvas动画导出视频
  • Nodejs和JavaWeb协助开发
  • vue总结
  • Zsh 开发指南(第十四篇 文件读写)
  • 包装类对象
  • 产品三维模型在线预览
  • 持续集成与持续部署宝典Part 2:创建持续集成流水线
  • 大型网站性能监测、分析与优化常见问题QA
  • 分享几个不错的工具
  • 后端_ThinkPHP5
  • 警报:线上事故之CountDownLatch的威力
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • ​七周四次课(5月9日)iptables filter表案例、iptables nat表应用
  • # wps必须要登录激活才能使用吗?
  • ###51单片机学习(2)-----如何通过C语言运用延时函数设计LED流水灯
  • #70结构体案例1(导师,学生,成绩)
  • #多叉树深度遍历_结合深度学习的视频编码方法--帧内预测
  • #图像处理
  • $.proxy和$.extend
  • (2)(2.10) LTM telemetry
  • (21)起落架/可伸缩相机支架
  • (html5)在移动端input输入搜索项后 输入法下面为什么不想百度那样出现前往? 而我的出现的是换行...
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • (附源码)spring boot建达集团公司平台 毕业设计 141538
  • (附源码)spring boot球鞋文化交流论坛 毕业设计 141436
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理 第13章 项目资源管理(七)
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理第3章 信息系统治理(一)
  • (十六)Flask之蓝图
  • (一)VirtualBox安装增强功能
  • (原+转)Ubuntu16.04软件中心闪退及wifi消失
  • (原創) 如何安裝Linux版本的Quartus II? (SOC) (Quartus II) (Linux) (RedHat) (VirtualBox)
  • (转)shell调试方法
  • (转)自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
  • .gitignore文件---让git自动忽略指定文件