比赛链接:Here

1530A. Binary Decimal

现在规定一种只由0和1组成的数字,我们称这种数字为二进制数字,例如10,1010111,给定一个数n,求该数字最少由多少个二进制数字组成.


水题,

每取一个二进制数字,可以使得原数字n上各位都减小1或者0,为了使次数尽可能地小,那么当原数字n上各位不为0的时候都应该-1,那么最小的次数就是各位上最大的数字

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
string s; cin >> s;
int cnt = s[0] - '0';
for (int i = 1; i < s.size(); ++i)cnt = max(s[i] - '0', cnt);
cout << cnt << "\n";
}
}

1530B. Putting Plates

给定一个高为h,宽为w的网格,你可以在网格的四个边缘处,放置一个盘子,每个盘子的四周都不能有别的盘子(四周指的是最近的8个格子),请输出一个种安排方式.


构造模拟题,首先为了使个数尽可能多,那么一定是从第一个开始放置,然后检测后面是否合法,如果合法就放下盘子,如果不合法就跳过.

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, m;
cin >> n >> m;
vector<std::string> s(n, string(m, '0'));
for (int i = 0; i < m; i += 2) {
s[0][i] = '1';
}
for (int i = 1; i < n; i++) {
if (s[i - 1][m - 1] != '1' && s[i - 1][m - 2] != '1') {
s[i][m - 1] = '1';
}
}
for (int i = m - 2; i >= 0; i--) {
if (s[n - 1][i + 1] != '1' && s[n - 2][i + 1] != '1') {
s[n - 1][i] = '1';
}
}
for (int i = n - 2; i > 1; i--) {
if (s[i + 1][0] != '1' && s[i + 1][1] != '1') {
s[i][0] = '1';
}
} for (int i = 0; i < n; i++) {
cout << s[i] << "\n";
}
}
}

1530C. Pursuit

二分,

给t组样例

每组样例给n个数

a[1] , a[2] , a[3] ...... a[n]

b[1] , b[2] , b[3] ...... b[n]

数据保证(0 <= a[i] , b[i] <= 100 , t组样例n的总和小于1e5)

a[i]表示第一个人在i这个阶段的分数

b[i]表示第二个人在i这个阶段的分数

现在只给了n个阶段每个人的分数

后面若干个阶段的分数值0到100之间都有可能

现在定义一个人在i这个阶段的得分为

从i个分数中取出 i - i / 4 个最大的分数相加即为

在i阶段的分数

问在n这个阶段是否第一个人的得分大于第二个人的得分

如果可以输出0

如果不行输出最少加几个阶段

使得第一个人的得分大于等于第二个人的得分

const int N = 1e6 + 10;
int a[N], b[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n;
cin >> n;
for (int i = 1; i <= n; ++i)cin >> a[i];
for (int i = 1; i <= n; ++i)cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n); auto check = [&](int k) {
int m = n + k, rm = m - m / 4;
int A = 0, B = 0;
for (int i = 1; i <= k; ++i) a[n + i] = 100;
for (int i = m; i > m - rm; --i)A += a[i];
for (int i = n; i > max(0, n - rm); --i)B += b[i];
return A >= B;
}; if (check(0))cout << "0\n";
else {
int l = 0, r = n;
while (r - l > 1) {
ll mid = (l + r) >> 1;
if (check(mid))r = mid;
else l = mid;
}
cout << r << "\n";
}
}
}

当然既然要让a的分数要大于等于b的分数

那么a[n+1] , a[n+2] , a[n+3] ......都应该是100

b[n+1] , b[n+2] , b[n+3] ....... 都应该是0

所以从大到小排序之后 用前缀和优化到 \(\mathcal{O}(n)\) 也是可以做的

1530D. Secret Santa

图论,

#include <bits/stdc++.h>
using namespace std;
using ll = long long; // jiangly TQL
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n;
cin >> n; int ans = 0;
vector<int> a(n), b(n, -1), c(n, -1);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
if (c[a[i]] < 0) {
b[i] = a[i];
c[a[i]] = i;
ans++;
}
} vector<int> u, v;
for (int i = 0; i < n; i++) {
if (c[i] >= 0) continue;
int j = i;
while (b[j] >= 0) j = b[j];
u.push_back(i);
v.push_back(j);
} if (!u.empty()) {
if (u.size() > 1 || u[0] != v[0]) {
for (int i = 0; i < int(u.size()); i++)
b[v[i]] = u[(i + 1) % u.size()];
} else {
int x = u[0];
int y = a[x];
b[x] = y;
b[c[y]] = x;
}
} cout << ans << "\n";
for (int i = 0; i < n; i++)
cout << b[i] + 1 << " \n"[i == n - 1];
}
}

Codeforces Round #733 (Div. 1 + Div. 2)的更多相关文章

  1. Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)

    Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...

  2. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  3. [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)

    [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...

  4. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  5. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  6. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  7. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  8. Educational Codeforces Round 59 (Rated for Div. 2) DE题解

    Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...

  9. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...

  10. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

随机推荐

  1. 深入了解Rabbit加密技术:原理、实现与应用

    一.引言 在信息时代,数据安全愈发受到重视,加密技术作为保障信息安全的核心手段,得到了广泛的研究与应用.Rabbit加密技术作为一种新型加密方法,具有较高的安全性和便捷性.本文将对Rabbit加密技术 ...

  2. 用友NCC&WMS&泛微 系统对接案例分享

    用户故事 产品版本:NCC2105 故事是这么开始的,用友全国伙伴社区的社区成员,对我们的多系统集成架构很感兴趣,经常跟我讨论相关系统集成层面的问题:随着企业的发展,由于信息产业的技术含量高,信息系统 ...

  3. 效率工具:Hutool 嘎嘎香,被秀到了!

    在日常开发中,我们会使用很多工具类来提升项目开发的速度,而国内用的比较多的 Hutool 框架,就是其中之一. 先来看官方对于 Hutool 的定义: Hutool 是一个小而全的 Java 工具类库 ...

  4. HDU 1108

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. 华企盾DSC登录控制台提示查询数据库错误

    解决方法:服务器防火墙已经关了,查看控制台日志,如出现下图2问题升级到最新版即可解决,否则需要找研发处理

  6. 获取微信的token工具类

    import cn.hutool.extra.spring.SpringUtil; import cn.hutool.http.HttpUtil; import cn.RedisUtil; impor ...

  7. 尚医通项目学习若依+springboot+springsecurity+redis+fastjson

    尚医通 [基于若依快速开发医疗系统] 主要内容 学习目标 项目简介 一款医疗平台. 系统包含:系统管理.药品进销存管理.看病就诊.收费管理.检查管理.数据统计等. 涉及技术 SpringBoot.My ...

  8. 『Flutter』开发环境搭建

    1.前言 大家好,我是 BNTang,今天给大家介绍一下 Flutter 的开发环境搭建.在之前我已经将 Dart 的基本语法给大家介绍了,所以今天就不再介绍 Dart 的基本语法了,直接进入 Flu ...

  9. Linux的一些的常用命令

    小杰笔记: 记录一下Linux的一些常见命令: 1:Linux关机与重启的命令: shutdown:关机 shutdown -h 30 30秒后关机 reboot 重启 sync:将数据由内存同步到硬 ...

  10. html2pdf

    nodejs 生成pdf比较靠谱,使用chrome核心渲染: puppeteer / phantom 爬虫都好用 good