Codeforces Round #519 题解
A. Elections
题意概述
给出 \(a_1, \ldots, a_n\),求最小的 \(k (k \ge \max a_i)\), 使得 \(\sum_{i=1}^n a_i < \sum_{i=1}^n (k-a_i)\) 原题链接
解题思路
数据范围小,直接枚举就好了
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
long long sum = 0;
int mx = 0;
for(int i=0; i<n; i++) {
int x;
cin >> x;
sum+=x;
if(x>mx) mx = x;
}
int start = sum*2/n;
if(start < mx) start = mx;
for(int i=start; ;i++) {
if(i*n > sum*2) {cout << i << endl;break;}
}
return 0;
}
B. Lost Array
题意概述
有一个数组 \(x_0, x_1, \ldots, x_{k-1}\) . 由它可以得到另一个数组 $$
a_i=\left{\begin{array}{ll}
0& i=0,\
x_{(i-1)\bmod k} + a_{i-1}& 1 \le i \le n
\end{array}\right.
### 解题思路
根据公式可发现,$a_i - a_{i-1} = x_{(i-1)\bmod k}$ , 若 $k = n$ 则得到一个可行的 $ a $ , 再枚举 $k$,判断在 $a$ 中是否 $k$个一组循环即可
### 代码
```c++
#include <bits/stdc++.h>
using namespace std;
int a[2000],b[2000];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for(int i=1; i<=n; i++) {
cin >> a[i];
b[i] = a[i]-a[i-1];
}
vector<int > ans;
for(int i=1; i<=n; i++){
bool flag = true;
for(int j=1; j<=i; j++) {
int ti = n/i; if(n%i) ti++;
for(int k=0; k<ti; k++) {
if((k+1)*i+j<=n){
if(b[k*i+j]==b[(k+1)*i+j]) {
}else {
flag = false;
break;
}
}
}
if(flag==false) break;
}
if(flag) ans.push_back(i);
}
cout << ans.size() << endl;
for(auto i : ans) cout << i << " ";
return 0;
}
```
## C. Smallest Word
### 题意概述
给出一个只包含字符 a 和 b 的串 s,对于从左到右每一个前缀,都可以选择进行翻转或者不翻转,使得最后这个字符串的字典序最小<a href=" http://codeforces.com/contest/1043/problem/C">原题链接</a>
### 解题思路
通过翻转一定可以使得所有的a在前面,b在后面,从而使字典序最小。
粗略证明:
* 假设当前的前缀子串满足字符 'a' 和 'b' 分别在该子串的两端( 如[aabb], [baa]),那么下一个前缀子串也一定满足这个性质(如果不满足,可通过翻转当前的前缀子串来使下一个前缀子串满足, 如[aaabb]a 翻转 [bbaaa]a)
* 其中第一个前缀子串一定满足该性质,递推得证
所以只需要找到由右至左第一个 'a' 的位置,然后从它开始向左遍历,每当 $s_i \neq s_{i+1}$ 那么需要翻转,否则不翻转
### 代码
```c++
#include <bits/stdc++.h>
using namespace std;
char s[2000];
int ans[2000];
int main() {
ios::sync_with_stdio(false);
cin >> s;
int pos = -1;
for(int i=strlen(s)-1; i>=0; i--) {
if(s[i] == 'a') {
pos = i;
break;
}
}
if(pos==-1) {
}
ans[pos] = 1;
for(int i=pos-1; i>=0; i--) {
if(s[i] != s[i+1]) ans[i] = 1;
else ans[i] = 0;
}
for(int i=0; i<strlen(s); i++) {
cout << ans[i] << " ";
}
return 0;
}
```
## D. Mysterious Crime
### 题意概述
给出 m 组 1~n 的排列,每一组选择删除一些前缀和后缀,使得所有组剩下的部分的数字以及剩下的数字的顺序都相同,求有多少种删除方法。
### 解题思路
首先至少有 n 种方法,即每组都删到只剩一个相同的数字为止
当某一个连续区间在 m 组中都出现时,答案+1
所以可以在每一组中,记录某个数的下一个数。当这个关系在其他组不成立时,则这一组数字对答案没有贡献
当连续区间较大时,区间长度每+1,答案 += 当前区间长度
<a href=" http://codeforces.com/contest/1043/problem/D">原题链接</a>
(表述不清晰。留坑)
### 代码
```c++
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int a[maxn],f[maxn];
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++) {
cin >> a[i];
f[a[i-1]] = a[i];
}f[a[n]] = n+1;
for(int i=1; i<m; i++) {
for(int i=1; i<=n; i++) {
cin >> a[i];
if((i-1) && f[a[i-1]]!=a[i]) f[a[i-1]]=-1;
} if(f[a[n]] != n+1) f[a[n]]=-1;
}
int len = 0;long long ans = 0;
for(int i=1; i<n; i++) {
if(f[a[i]] > 0)
if(f[a[i-1]] > 0) {
len ++;
ans += len;
} else {
len = 1;
ans += len;
}
}
cout << n+ans << endl;
return 0;
}
```
## E. Train Hard, Win Easy
### 题意概述
留坑<a href=" http://codeforces.com/contest/1043/problem/E">原题链接</a>
### 解题思路
留坑
### 代码
```c++
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+7;
int f[maxn];
struct __ {
long long x, y, id;
bool operator<(const __ & b) const {
return (x-y) > (b.x-b.y);
}
}a[maxn];
long long sum[maxn];
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for(int i=0; i<n; i++) {
cin >> a[i].x >> a[i].y;
a[i].id = i;
}
sort(a, a+n);
for(int i=0; i<n; i++) {
f[a[i].id] = i;
}
long long s=0;
for(int i=0; i<n; i++) {
sum[i] = a[i].x*i+(n-1-i)*a[i].y;
}
for(int i=1; i<n; i++) {
s+=a[i-1].y;
sum[i]+=s;
}
s = 0;
for(int i=n-2; i>=0; i--) {
s+=a[i+1].x;
sum[i]+=s;
}
for(int i=0; i<m; i++ ) {
int s, t;
cin >> s1 >> t1;
s1--;t1--;
s1 = f[s1];
t1 = f[t1];
long long sub = 0;
if(a[s1].x+a[t1].y<a[s1].y+a[t1].x){
sub = a[s1].x + a[t1].y;
}else {
sub = a[t1].x + a[s1].y;
}
sum[s1] -= sub;
sum[t1] -= sub;
}
for(int i=0; i<n; i++) {
cout << sum[f[i]] << " ";
}
return 0;
}
```
## F. Make It One
### 题意概述
留坑<a href="http://codeforces.com/contest/1043/problem/G">赶紧补了</a>
### 解题思路
留坑
### 代码
留坑
## G. Speckled Band
### 题意概述
深渊巨坑 <a href="http://codeforces.com/contest/1043/problem/G">有生之年</a>
### 解题思路
深渊巨坑
### 代码
深渊巨坑\]
Codeforces Round #519 题解的更多相关文章
- Codeforces Round #519 by Botan Investments(前五题题解)
开个新号打打codeforces(以前那号玩废了),结果就遇到了这么难一套.touristD题用了map,被卡掉了(其实是对cf的评测机过分自信),G题没过, 700多行代码,码力惊人.关键是这次to ...
- Codeforces Round #519 by Botan Investments
Codeforces Round #519 by Botan Investments #include<bits/stdc++.h> #include<iostream> #i ...
- Codeforces Round #556 题解
Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...
- Codeforces Round #569 题解
Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作 ...
- Codeforces Round #557 题解【更完了】
Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...
- CFEducational Codeforces Round 66题解报告
CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...
- Codeforces Round #542 题解
Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...
- [题解]Codeforces Round #519 - D. Mysterious Crime
[题目] D. Mysterious Crime [描述] 有m个n排列,求一共有多少个公共子段. 数据范围:1<=n<=100000,1<=m<=10 [思路] 对于第一个排 ...
- [题解]Codeforces Round #519 - C. Smallest Word
[题目] C. Smallest Word [描述] IA有一个由若干个'a'和'b'组成的字符串,IA可以翻转该字符串的任意长的前缀,IA想通过这样的操作得到一个字典序最小的字符串,求一种可能的翻转 ...
随机推荐
- effective c++ 笔记 (23-25)
//---------------------------15/04/08---------------------------- //#23 宁以non_member.non_friend替换m ...
- index索引的一些简单理解
index索引(普通索引,允许出现相同的索引内容) 1.索引 索引是在数据量和访问量较大的时候,而出现的一种优化数据库的手段 索引可以提高查询(select)的效率,但相应的,它的 INSERT 与 ...
- Scrapy框架中的CrawlSpider
小思考:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话,有几种实现方法? 方法一:基于Scrapy框架中的Spider的递归爬取进行实现(Request模块递归回调parse方法). 方法二: ...
- Kaggle: Google Analytics Customer Revenue Prediction EDA
前言 内容提要 本文为Kaggle竞赛 Google Analytics Customer Revenue Prediction 的探索性分析 题目要求根据历史顾客访问GStore的数据,预测其中部分 ...
- Python读取ini配置文件封装方法
读取配置文件 ----rw_ini.py from configparser import ConfigParser def read_config(config_file_path:str): &q ...
- 二叉树 c++
树 非空树 有一个(root)根节点r 其余节点可分为m个互不相交的有限集(子树)T1....Tm 具有n个节点的树,具有(n-1)条连接(指针域),需要构成结构体,尽可能减少空间域的浪费,使用儿子兄 ...
- win10系统安装web3js的正确方法
在安装web3的时候 用npm install web3 –save-dev 在win10系统下会一直安装不成功.后来换用了 cnpm install web3 –save-dev 安装时候报出:C ...
- 数据库——SQL数据单表查询
数据查询 语句格式 SELECT [ALL|DISTINCT] <目标列表达式> [,<目标列表达式>] … FROM <表或视图名>[,<表或视图名&g ...
- Linux内核分析 笔记二 操作系统是如何工作的 ——by王玥
一.知识要点 1.计算机是如何工作的?(总结)——三个法宝 存储程序计算机工作模型,计算机系统最最基础性的逻辑结构: 函数调用堆栈,高级语言得以运行的基础,只有机器语言和汇编语言的时候堆栈机制对于计算 ...
- [Latex] Travis-CI与Latex构建开源中文PDF
博主有一本开源书籍,用 latex 排版,托管在Github上.但用 latex 不像是 Markdown,当tex文本更新时,用于最终浏览的PDF文件很难得到及时的更新, 所以博主一直想找到一套工具 ...