Codeforces Round #640 (Div. 4)
比赛链接:https://codeforces.com/contest/1352
A - Sum of Round Numbers
题意
将一个十进制数的每一个非零位分离出来。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
string s; cin >> s;
int n = s.size();
vector<string> ans;
for (int i = n - 1; i >= 0; i--) {
if (s[i] != '0') {
ans.push_back(s[i] + string(n - 1 - i, '0'));
}
}
cout << ans.size() << "\n";
for (auto i : ans) cout << i << ' ';
cout << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
B - Same Parity Summands
题意
将整数 n 分解为 k 个奇偶性相同的数。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n, k; cin >> n >> k;
int n1 = n - (k - 1), n2 = n - (k - 1) * 2;
if (n1 > 0 and n1 % 2 == 1) {
cout << "YES\n";
for (int i = 0; i < k - 1; i++) cout << "1 ";
cout << n1 << "\n";
} else if (n2 > 0 and n2 % 2 == 0) {
cout << "YES\n";
for (int i = 0; i < k - 1; i++) cout << "2 ";
cout << n2 << "\n";
} else {
cout << "NO" << "\n";
}
} int main() {
int t; cin >> t;
while (t--) solve();
}
C - K-th Not Divisible by n
题意
输出第 k 个不能被 n 整除的数。
题解
两个 n 之间有 n - 1 个不能被 n 整除的数,找出 k 中有多少个完整的 n - 1 区间,再对 n - 1 取余即可。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
long long n, k; cin >> n >> k;
if (k % (n - 1) == 0)
cout << k / (n - 1) * n - 1 << "\n";
else
cout << k / (n - 1) * n + k % (n - 1) << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
D - Alice, Bob and Candies
题意
n 堆糖果排成一排,Alice 只能从左边取,Bob 只能从右边取,每次一人取得的糖果数需多于另一人上一次取得的糖果数,问所有糖果取完时二人共取了多少次,以及各自取得的糖果个数。
题解
模拟即可。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int a[n] = {}; for (auto &i : a) cin >> i;
int l = 0, r = n - 1;
int ans_l = 0, ans_r = 0;
int pre_l = 0, pre_r = 0;
int i;
for (i = 0; l <= r; i++) {
int sum = 0;
if (i % 2 == 0) {
while (l <= r and sum <= pre_r) {
sum += a[l];
++l;
}
ans_l += sum;
pre_l = sum;
} else {
while (r >= l and sum <= pre_l) {
sum += a[r];
--r;
}
ans_r += sum;
pre_r = sum;
}
}
cout << i << ' ' << ans_l << ' ' << ans_r << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
E - Special Elements
题意
统计数组 a 中有多少元素可以被连续子数组加和求得。
题解
数据范围较小,$O_{(n^2)}$ 枚举即可。
代码
#include <bits/stdc++.h>
using namespace std; const int M = 8100;
int n, a[M], cnt[M]; void solve() {
fill(cnt, cnt + M, 0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i], ++cnt[a[i]];
}
int ans = 0;
for (int i = 0; i < n; i++) {
int sum = a[i];
for (int j = i + 1; j < n; j++) {
sum += a[j];
if (sum < M and cnt[sum]) {
ans += cnt[sum];
cnt[sum] = 0;
}
}
}
cout << ans << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
F - Binary String Reconstruction
题意
构造一个 01 串,要求:
- 00 的个数为 n0 个
- 01 的个数为 n1 个
- 11 的个数为 n2 个
题解
依次构造 11,10,00 即可。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n0, n1, n2; cin >> n0 >> n1 >> n2;
vector<int> ans;
if (n1 or n2) ans.push_back(1);
for (int i = 0; i < n2; i++) ans.push_back(1);
for (int i = 0; i < n1 / 2; i++) {
ans.push_back(0);
ans.push_back(1);
}
if (n1 & 1) {
ans.push_back(0);
for (int i = 0; i < n0; i++) ans.push_back(0);
} else {
if (ans.size()) {
ans.pop_back();
for (int i = 0; i < n0; i++) ans.push_back(0);
ans.push_back(1);
} else {
for (int i = 0; i < n0 + 1; i++) ans.push_back(0);
}
}
for (auto i : ans) cout << i;
cout << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
G - Special Permutation
题意
构造数 n 的一个排列,使得相邻两数相差在 [2, 4] 之间。
题解
顺着 3 1 4 2 构造即可。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
if (n <= 3) {
cout << -1 << "\n";
return;
} else {
for (int i = n - (n % 2 == 0); i >= 5; i -= 2) cout << i << ' ';
cout << "3 1 4 2 ";
for (int i = 6; i <= n - (n % 2 == 1); i += 2) cout << i << ' ';
cout << "\n";
}
} int main() {
int t; cin >> t;
while (t--) solve();
}
Codeforces Round #640 (Div. 4)的更多相关文章
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- ThinkPHP5表单令牌刷新
制作登录页面的时候,加入了表单令牌,账号和密码输入错误后,再登录的话,会提示表单令牌错误, 这是因为旧的令牌已经过期了,我们要处理下前端的token,修复的办法,在路由文件下加入 //刷新表单令牌,然 ...
- Docker学习笔记之搭建Docker私有仓库
Docker仓库服务器名为Docker注册(registry)服务器.可以使用docker push命令将镜像上传到注册服务器,也可以使用docker pull命令下载服务器的镜像. Docker注册 ...
- 负载均衡和故障转换(Failover)的连接RAC方法
TAF:Transparent Application Failover,透明的应用切换,即在切换的过程中,用户感知不到.可以实现会话的切换(无法实现事务的切换,即没有提交的事务会回滚),即在不断开连 ...
- 使用axis1.4生成webservice的客户端代码
webservice服务端: https://blog.csdn.net/ghsau/article/details/12714965 跟据WSDL文件地址生成客服端代码: 1.下载 axis1.4 ...
- Poj-P2533题解【动态规划】
本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: http://poj.org/problem?id=2533 题目描述: 如果ai1 < ...
- 前端知识(一)05 axios-谷粒学院
目录 一.axios的作用 二.axios实例 1.复制js资源 2.创建 axios.html 3.引入js 4.启动课程中心微服务 5.编写js 6.html渲染数据 7.跨域 8.使用生命周期函 ...
- FPGA仿真的概念及语法特点
以下是特权同学<FPGA设计+实战演练>书中的描述: 一个正规的设计需要花费在验证上的工作量,往往可能会占到整个开发流程的70%左右.验证通常分为仿真验证和板机验证. ...
- WinForm中实现按Enter将光标移动到下一个文本框
首先窗体加载出来是上面这个样子.有五个文本框,我们要实现的功能就是输入姓名后按Enter,使光标直接定位到手机号中. 在页面加载的时候我们就要获取所有文本框控件,并添加回车事件 private voi ...
- charles安装使用乱码连手机等问题解决方案
捣鼓半天终于安装好了,给大家分享下我的过程 1.安装, 正常网上安装即可,我安装了个有汉化包的,,推荐链接 安装方法下载破解版,安装即可 安装包地址:https://pan.baidu.com/s/1 ...
- namedtuple
Python的namedtuple使用详解_kongxx的专栏-CSDN博客_namedtuple https://blog.csdn.net/kongxx/article/details/51553 ...