比赛链接: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. Windows软件Everything的配置

    Everything配置 Everything是一款Windows下的搜索软件,怎么安装应该不难.这里说一下个人使用的两个习惯. 主要就两点,一个是快捷键,一个是搜索路径 1. 快捷键 配置快捷键,点 ...

  2. 改进你的c#代码的5个技巧(三)

    本文完全独立于前两篇文章.如果你喜欢它们,我希望你也会喜欢这个.在上一篇文章中,我展示了哪种方法更快,并比较了代码的执行速度.在本文中,我将展示不同代码片段的内存消耗情况.为了显示内存映射和分配图,我 ...

  3. 【剑指 Offer】03.数组中重复的数字

    题目描述 找出数组中重复的数字. 在一个长度为 n 的数组 nums 里的所有数字都在 0-n-1 的范围内.数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次.请找出数组中 ...

  4. 编译安装 nginx -1.14.2

    编译安装 nginx -1.14.2 1 ) 下载nginx-1.14.2 源码包: wget http://nginx.org/download/nginx-1.14.2.tar.gz 2 ) 编译 ...

  5. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例

    什么是表存储 Azure 表存储是一项用于在云中存储结构化 NoSQL 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...

  6. 爬虫学习(三)Chrome浏览器使用

    一.新建隐身窗口 在打开隐身窗口的时候,第一次请求某个网站是没有携带cookie的,和代码请求一个网站一样,不携带cookie.这样就能够尽可能的理解代码请求某个网站的结果:除非数据是通过js加载出来 ...

  7. [USACO13DEC]牛奶调度Milk Scheduling

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4096 容易想到的一个测略就是,优先考虑结束时间小的牛.所以我们对所有牛按照结束时间排序.然 ...

  8. mastercam2018安装教程

    安装前先关闭杀毒软件和360卫士,注意安装路径不能有中文,安装包路径也不要有中文. [安装环境]:Win7/Win8/Win10 1.选中[Mastercam2018]压缩包,鼠标右击选择[解压到Ma ...

  9. es6语法详解

    什么是ECMAScript? ECMAScript是浏览器脚本语言的规范,而我们熟知的js语言,如JavaScript则是规范的具体实现.es6就好比Java的jdk. 一.es6语法详解:let声明 ...

  10. JAVA SSM整合流程以及注意点

    1.搭建整合环境 整合说明:SSM整合可以使用多种方式,咱们会选择XML + 注解的方式 先搭建整合的环境 先把Spring的配置搭建完成 再使用Spring整合SpringMVC框架 最后使用Spr ...