Codeforces Round #733 (Div. 1 + Div. 2)
比赛链接: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)的更多相关文章
- 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 ...
- Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)
这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...
- [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)
[Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Educational Codeforces Round 59 (Rated for Div. 2) DE题解
Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest
Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...
随机推荐
- Ubuntu 18.04替换默认软件源
安装Ubuntu 18.04后,默认源在国外,可以替换为国内的源以提升访问速度 参考https://mirrors.ustc.edu.cn/repogen/ sudo vi /etc/apt/sour ...
- Netty源码学习6——netty编码解码器&粘包半包问题的解决
系列文章目录和关于我 零丶引入 经过<Netty源码学习4--服务端是处理新连接的&netty的reactor模式和<Netty源码学习5--服务端是如何读取数据的>的学习, ...
- BI软件是什么?应用BI工具能给企业带来什么
BI软件是指利用数据挖掘.分析和可视化等技术,将企业内部和外部数据转化为有价值的信息和洞察,以帮助企业支持业务决策和优化业务流程的工具和应用程序.常见的BI软件包括Datainside.QlikVie ...
- 小程序的登录授权与退出功能(wx.getUserProfile)
一.授权登录:wx.getUserProfile 1.使用wx.getUserProfile实现登录 1.javascript: login(){ wx.getUserProfile({ desc: ...
- charles谷歌浏览器抓包方法
charles谷歌浏览器抓包方法 在工作中,我们会在PC电脑上测试页面,查看后端接口,我们会选择浏览器F12的功能来查看后端请求的接口,那我们能不能用charles抓包工具去抓呢?下面简答介绍一下ch ...
- [ABC281F] Xor Minimization
div class="part"> Problem Statement You are given a sequence of non-negative integers $ ...
- OkHttp3发送http请求
导入依赖 <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp --> <dependency> ...
- 子类Dog根据自己的需要,重写了Animal方法
子类Dog根据自己的需要,重写了Animal方法 package com.guoba.method; class Animal{ public void move(){ System.out.prin ...
- Python 潮流周刊第 33 期(摘要)
本周刊由 Python猫 出品,精心筛选国内外的 250+ 信息源,为你挑选最值得分享的文章.教程.开源项目.软件工具.播客和视频.热门话题等内容.愿景:帮助所有读者精进 Python 技术,并增长职 ...
- 从零玩转SpringSecurity+JWT整合前后端分离-从零玩转springsecurityjwt整合前后端分离
title: 从零玩转SpringSecurity+JWT整合前后端分离 date: 2021-05-06 14:56:57.699 updated: 2021-12-26 17:43:19.478 ...