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想通过这样的操作得到一个字典序最小的字符串,求一种可能的翻转 ...
随机推荐
- REST-framework快速构建API--四部曲
代码目录结构: 一.使用原生APIView 使用rest-framework原生的APIView实现过程: 以url(r'^books/$', views.BookView.as_view(),nam ...
- 【LeetCode】数组--合并区间(56)
写在前面 老粉丝可能知道现阶段的LeetCode刷题将按照某一个特定的专题进行,之前的[贪心算法]已经结束,虽然只有三个题却包含了简单,中等,困难这三个维度,今天介绍的是第二个专题[数组] 数组( ...
- 共享服务Samba,实现liunx与Windows文件共享
Samba服务程序 是一款SMB协议并有服务器和客户端组成的开源文件共享软件,实现了Linux 与Windows系统之间的文件共享 Samba的配置文件有太多注释的东西,为了方便使用下面的命令,可以更 ...
- Windows 使用 StarWind 创建的 Oracle RAC环境 异常关机之后的处理过程
创建好了 虚拟机之后发现 偶尔会出现 蓝屏重启的现象, 这个时候 需要进行 异常处理 确定虚拟机已经开机之后 1. 打开iscsi的连接设备, 确认 iscsi的正常连接到虚拟机的 存储设备 注意 r ...
- [51CTO]服务器虚拟化开源技术主流架构之争
服务器虚拟化开源技术主流架构之争 http://virtual.51cto.com/art/201812/589084.htm 大部分客户已经是KVM+OpenStack的架构了 我所见到的 工商云 ...
- Redis的相关问题总结
一.Redis的优缺点及适用场景 Redis 是一个基于内存的高性能key-value数据库.很像memcached,整个数据库统统加载在内存当中进行操作,定期通过异步操作把数据库数据flush到硬盘 ...
- Hibernate性能优化之EHCache缓存
像Hibernate这种ORM框架,相较于JDBC操作,需要有更复杂的机制来实现映射.对象状态管理等,因此在性能和效率上有一定的损耗. 在保证避免映射产生低效的SQL操作外,缓存是提升Hibernat ...
- browser-sync & http server
browser-sync & http server browser-sync https://www.browsersync.io/ usage # step 1 $ npm install ...
- 窗体的构造函数和OnCreate事件
窗体的构造函数和创建事件和OldCreateOrder属性有很大的关系. 情况1: 如果窗体继承自TForm,且有如下形式: 1. constructor TForm1.Create(AOw ...
- 学习官方示例 - TForm.BorderIcons
本例用一行代码禁用了最大化按钮. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphi ...