比赛链接: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)的更多相关文章

  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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. Jenkins-自动部署,备份

    Jenkins-自动部署,备份 问题导入: 环境: CentOS 7,   Tomcat 8.5,   Jdk 1.8,   Maven 3.25 ,Jenkins war包 2.x 原因: 每次部署 ...

  2. Ocelot一个优秀的.NET API网关框架

    1 什么是Ocelot? Ocelot是一个用.NET Core实现并且开源的API网关,它功能强大,包括了:路由.请求聚合.服务发现.认证.鉴权.限流熔断.并内置了负载均衡器与Service Fab ...

  3. Centos7安装Jenkins和目录迁移

    Centos7安装Jenkins和目录迁移 内容: 安装Jenkins和相关的配置 尝试目录迁移,模拟磁盘空间不足 1. 安装Jenkins和配置 安装 根据Jenkins的官方安装指引,安装步骤如下 ...

  4. 【排序基础】1、选择排序法 - Selection Sort

    文章目录 选择排序法 - Selection Sort 为什么要学习O(n^2)的排序算法? 选择排序算法思想 操作:选择排序代码实现 选择排序法 - Selection Sort 简单记录-bobo ...

  5. 【TNS】listener.ora模板;tnsnames.ora模板

    好多人使用监听的时候误操作,将监听弄的不好使了,这次这个模板,不光是针对大家出现的这种问题,也是给我自己留一个记录,方便他人,方便自己. listener.ora模板样例 -------------- ...

  6. SDUST数据结构 - chap8 查找

    选择题: 函数题: 6-1 二分查找: 裁判测试程序样例: #include <stdio.h> #include <stdlib.h> #define MAXSIZE 10 ...

  7. JavaScript中的构造函数和原型!

    JavaScript中的原型! 原型的内容是涉及到JavaScript中的构造函数的 每一个构造函数都有一个原型对象!prototype 他的作用是 共享方法!还可以扩展内置对象[对原来的内置对象进行 ...

  8. 攻击JWT的一些方法

    JWT安全隐患之绕过访问控制 https://mp.weixin.qq.com/s/xe8vOVhaysmgvxl-A3nkBA 记录一次JWT的越权渗透测试 https://mp.weixin.qq ...

  9. Java面向对象(三)—— 继承

    标签: java 继承 抽象类 this super abstract 概述 多个类中存在相同的属性和行为的时候,将这些内容抽取到单独一个类中,那么多个类无需在定义这些属性和行为,只要继承那个类即可. ...

  10. 本地MarkDown优雅发表

    本地MarkDown优雅发表 前言 身为一名程序员,记录笔记.发表博客首选便是MarkDown,现在网上有好多发表博客的地方:CSDN.博客园.简书,甚至一些大佬都有自己专属博客,但自己最喜欢的还是博 ...