【cf比赛记录】Codeforces Round #600 (Div. 2)
Codeforces Round #600 (Div. 2) ---- 比赛传送门
昨晚成绩还好,AC A,B题,还能上分(到底有多菜)
补了C、D题,因为昨晚对C、D题已经有想法了,所以补起题来也快。(C题TLE了,D题想用并查集没好)
A
// http://codeforces.com/contest/1253/problem/A
/*
如果YES,则b[i] - a[i] 在一个区间里的差肯定是相同的且不小于0
*/
#include<iostream>
#include<cstdio>
using namespace std;
int a[100005], b[100005];
int tar[100005];
int T, n, l, r, k;
int main()
{
scanf("%d", &T);
while(T--){
bool flag = true;
int pla = -1, num = 0, x = -1; // pla 来存储第一个差不为 0 的位置 x 存第一个不为 0 的差值
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
for(int i = 0; i < n; i++){
scanf("%d", &b[i]);
tar[i] = b[i] - a[i];
if(tar[i] != 0) {
if(pla == -1) { pla = i; x = tar[i]; } // 找到第一个 不等的点
num++; // num 来记录有多少个不同点
}
}
if(pla == -1) printf("YES\n");
else {
for(int i = pla; i < n && num > 0; i++, num--){
if(tar[i] != x){ // 一个个校对
flag = false;
break;
}
}
if(x < 0) flag = false; // 特判第一个不等已经是 < 0 时
if(flag) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
B
// http://codeforces.com/contest/1253/problem/B
/*
因为分置的天数不需要最大或者最小,所以就直接处理最多天数的情况
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int num[1000006], c;
int in[1000006]; // 记录员工是否已上班已下班,0表示没上班,1表示还没下班,2表示已经下班
int ans[1000006], ans_count;
int n, a, tot, num_c, ans_c;
int main()
{
bool flag = true;
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%d", &a);
if(a > 0){
if(in[a] != 0) flag = false; // 如果已经上班了还上班,false
else { // 符合情况
in[a]++;
num[c++] = a; // 记录已经上班的员工
tot += a;
}
}
else {
if(in[-a] != 1) flag = false; // 已经下班了或者还没上班还下班,false
else { // 符合情况
in[-a]++;
tot += a;
}
}
num_c++;
if(tot == 0){ // tot == 0的时候既公司没人的时候
ans[ans_c++] = num_c;
num_c = 0;
for(int j = 0; j < c; j++){ // 初始化 用 memset 会超时
in[num[j]] = 0;
}
c = 0; // 初始化
}
}
if(n & 1) flag = false; // 特判 n 为奇数时
if(tot != 0) flag = false; // 特判最后一天 tot != 0 即公司的员工有人还没下班
if(flag){ // 符合情况 输出答案
printf("%d\n", ans_c);
for(int i = 0; i < ans_c; i++){
printf("%d%c", ans[i], i == ans_c - 1 ? '\n' : ' ');
}
}
else printf("-1\n"); // 不符合情况时输出 -1
return 0;
}
C
参考题解(官方):

// http://codeforces.com/contest/1253/problem/C
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n, m;
int sweet[200005];
long long ans[200005];
// 前缀和 O(nlogn) ---- 主要用在了排序
int main(){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%d", &sweet[i]);
sort(sweet + 1, sweet + n + 1);
long long tot = 0;
for(int i = 1; i <= n; i++){
tot += sweet[i];
ans[i] = tot;
if(i > m){ // 当吃的比m大的时候,只是比 i - m 一天多了个 ans[i - m](可以在纸上写写)
ans[i] += ans[i - m]; // 前缀和
}
printf("%I64d%c", ans[i], i == n ? '\n' : ' ');
}
return 0;
}
/* O(n^2) TLE
int main()
{
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++){
scanf("%d", &sweet[i]);
}
sort(sweet, sweet + n);
double M = m;
for(int i = 1; i <= n; i++){
int day = ceil(i / M);
int eat = i;
int day_can = m;
int day_s = 1;
long long tot = 0;
while(eat > 0){ // 模拟操作
tot += sweet[eat - 1] * day_s;
// printf("tot:%I64d sweet:%d day_s:%d can:%d\n", tot, sweet[eat - 1], day_s, day_can);
day_can--;
if(day_can == 0){
day_s++;
day_can = m;
}
eat--;
}
// printf("\n");
ans[i] = tot;
// printf("day:%d\n", day);
}
for(int i = 0; i < n; i++){
printf("%d%c", sweet[i], i == n - 1 ? '\n' : ' ');
}
for(int i = 1; i <= n; i++){
printf("%I64d%c", ans[i], i == n ? '\n' : ' ');
}
return 0;
}
*/
D
参考题解的出处在代码里
// http://codeforces.com/contest/1253/problem/D
// 参考:Marca 的 #65186644 的 AC 代码
#include<iostream>
#include<cstdio>
using namespace std;
int n, m, a, b, x, y, ans;
int par[200005];
void init(int n){
for(int i = 1; i <= n; i++) par[i] = i;
}
int ff(int x){
if(par[x] == x) return x;
else return par[x] = ff(par[x]);
}
// 并查集解法
int main()
{
scanf("%d %d", &n, &m);
init(n);
for(int i = 0; i < m; i++){
scanf("%d %d", &a, &b);
x = ff(a);
y = ff(b);
// 把点大的都做树的根节点
if(x > y) swap(x, y);
par[x] = y;
}
for(int i = 1; i <= n; i++){
x = ff(i); // ff函数已包含路径压缩
while(i < x){
y = ff(i);
if(x != y){ // 不在一个区间里 合并
ans++; // 路径 ++
// 把点大的做树的根节点
if(y > x) swap(x, y);
par[y] = x;
}
i++;
}
}
printf("%d\n", ans);
return 0;
}
记录我这菜鸟的成长经历

【cf比赛记录】Codeforces Round #600 (Div. 2)的更多相关文章
- Codeforces Round #600 (Div. 2) E. Antenna Coverage
Codeforces Round #600 (Div. 2) E. Antenna Coverage(dp) 题目链接 题意: m个Antenna,每个Antenna的位置是\(x_i\),分数是\( ...
- Codeforces Round #600 (Div. 2)E F
题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...
- Codeforces Round #600 (Div. 2)
传送门 A. Single Push 直接乱搞即可. Code /* * Author: heyuhhh * Created Time: 2019/11/16 22:36:20 */ #include ...
- Codeforces Round #600 (Div. 2) - B. Silly Mistake(模拟)
题意:有一个公司,每天有员工进出,$a[i]>0$时表示$a[i]$这个员工进入公司,$a[i]<0$时表示$-a[i]$这个员工出公司,公司对进出办公室有一些严格的规定 员工每天最多只能 ...
- B. Silly Mistake Codeforces Round #600 (Div. 2)
B. Silly Mistake 题目大意: 首先定义有效的一天: 每一个不同的数字只能进去一次,出来一次,正数代表进去,负数代表出来 每一个人不能过夜 不合理: 一个数字只有进去,或者只有出来则是无 ...
- Codeforces Round #600 (Div. 2) D题【并查集+思维】
题意:给你n个点,m条边,然后让你使得这个这个图成为一个协和图,需要加几条边.协和图就是,如果两个点之间有一条边,那么左端点与这之间任意一个点之间都要有条边. 思路:通过并查集不断维护连通量的最大编号 ...
- Codeforces Round #600 (Div. 2) D。 Harmonious Graph
#include<iostream> using namespace std ; ; int p[N]; int cnt; int find(int x) { if(p[x]!=x) p[ ...
- Codeforces Round #600 (Div. 2) C - Sweets Eating
#include<iostream> #include<algorithm> #include<cstring> using namespace std ; typ ...
- Codeforces Round #600 (Div. 2) A. Single Push
#include<iostream> #include<cstdio> #include<cstdlib> using namespace std; int T,n ...
随机推荐
- 二.HTML
1.HTML 1. <head></head>标签 <!DOCTYPE html> <!--统一规范--> <!----> <html ...
- English--consonant_摩擦音
consonant_摩擦音_[f]和[v].[s]和[z].[∫]和[ʒ] 摩擦音:理论上可以无限延长气流. [f]:噘嘴,上牙咬住下唇,送气,通过气流摩擦发音,声带不震动.knife.food.le ...
- 编写可维护的JavaScript-随笔(二)
一.注释 1. 单行注释 a) 以两个斜线开始,以行位结束 b) 独占一行的注释,用来解释下一行的代码, c) 注释行之前总有一个空行 d) 缩进层级与下一行代 ...
- css中absolute设置问题和如何让div居中
今天设置多个div到页面正中间的时候,在第一层<div class="map">中设置如下: .map{ position:absolute: top:50%; lef ...
- 爬虫requests库 之爬虫贴吧
首先要观察爬虫的URL规律,爬取一个贴吧所有页的数据,观察点击下一页时URL是如何变化的. 思路: 定义一个类,初始化方法什么都不用管 定义一个run方法,用来实现主要逻辑 3 class Tieba ...
- 最强在线文件格式转换(支持200+文件格式如常用的PDF,DOCX,JPG,GIF,MP3,MP4,FLV,MOBI)(通用)
网站展示:http://www.alltoall.net/ 分类简洁 支持的所有文件格式展示: 单独展示文档转换: 单独展示PDF转换:
- windows自动化-脚本案例
; Script Start - Add your code below here Run("D:\Navicat Premium\navicat.exe") Sleep(1000 ...
- App的开发过程(转载)
来源:https://www.cnblogs.com/sanwenyu/p/7234616.html 不同的项目管理模式或许会有完全不同的流程步骤.但是专业性几乎是保证产品质量的唯一准则. App的开 ...
- Java8新特性。
常用函数接口: 函数式接口: 函数式接口在Java中是指:有且仅有一个抽象方法的接口(可以含其他方法). 而Java中的函数式编程的体现就是Lambda. @FunctionalInterface 注 ...
- prometheus学习系列四: Prometheus详述
数据模型 Prometheus 是将所有数据存为时序数据. 每个时序数据是由指标名称和可选的键值对(称之为标签)唯一标识. 度量类型 counter: 单调递增的计数器,如果标识已经服务的请求数量可以 ...