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)的更多相关文章

  1. Codeforces Round #600 (Div. 2) E. Antenna Coverage

    Codeforces Round #600 (Div. 2) E. Antenna Coverage(dp) 题目链接 题意: m个Antenna,每个Antenna的位置是\(x_i\),分数是\( ...

  2. Codeforces Round #600 (Div. 2)E F

    题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...

  3. Codeforces Round #600 (Div. 2)

    传送门 A. Single Push 直接乱搞即可. Code /* * Author: heyuhhh * Created Time: 2019/11/16 22:36:20 */ #include ...

  4. Codeforces Round #600 (Div. 2) - B. Silly Mistake(模拟)

    题意:有一个公司,每天有员工进出,$a[i]>0$时表示$a[i]$这个员工进入公司,$a[i]<0$时表示$-a[i]$这个员工出公司,公司对进出办公室有一些严格的规定 员工每天最多只能 ...

  5. B. Silly Mistake Codeforces Round #600 (Div. 2)

    B. Silly Mistake 题目大意: 首先定义有效的一天: 每一个不同的数字只能进去一次,出来一次,正数代表进去,负数代表出来 每一个人不能过夜 不合理: 一个数字只有进去,或者只有出来则是无 ...

  6. Codeforces Round #600 (Div. 2) D题【并查集+思维】

    题意:给你n个点,m条边,然后让你使得这个这个图成为一个协和图,需要加几条边.协和图就是,如果两个点之间有一条边,那么左端点与这之间任意一个点之间都要有条边. 思路:通过并查集不断维护连通量的最大编号 ...

  7. 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[ ...

  8. Codeforces Round #600 (Div. 2) C - Sweets Eating

    #include<iostream> #include<algorithm> #include<cstring> using namespace std ; typ ...

  9. Codeforces Round #600 (Div. 2) A. Single Push

    #include<iostream> #include<cstdio> #include<cstdlib> using namespace std; int T,n ...

随机推荐

  1. Golang逃逸分析

    Golang逃逸分析 介绍逃逸分析的概念,go怎么开启逃逸分析的log. 以下资料来自互联网,有错误之处,请一定告之. sheepbao 2017.06.10 什么是逃逸分析 wiki上的定义 In ...

  2. 从 Vue 的视角学 React(三)—— 事件处理

    如果要处理某个元素的 click 事件,原生 js 可以直接为该元素添加一个 onclick 函数 Vue 封装了 v-on 指令,可以简化为 @click 并添加相应的函数 React 的开发思想是 ...

  3. ES6的新特性

    ECMAScript 6(简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,又称ECMAScript 2015.ES6就是ES2015. 虽然目前并不是所有 ...

  4. AngularJS 菜鸟

    AngualrJS是 JavaScript框架. <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/ang ...

  5. springboot:使用JPA-Hibernate

    步骤: 在pom.xml文件中添加mysql,spring-data-jpa的依赖. <!-- 添加mysql数据库驱动依赖--> <dependency> <group ...

  6. struts2启动报错:ERROR com.opensymphony.xwork2.conversion.impl.DefaultConversionPropertiesProcessor - Conversion registration error

    [framework] 2019-12-05 11:34:05,441 - org.springframework.web.context.ContextLoader -5352 [RMI TCP C ...

  7. markdown 格式测试

    Q1: before 与 afer 的而区别在哪? Q2: 如何预防"爆仓"? Q3: 在购买量 much > 库存量 num时, 把much自动改为num? -- 在t2的 ...

  8. 消息队列的作用以及kafka和activemq的对比

    背景分析 消息队列这个类型的组件一直是非常重要的组件,当经过两家企业后我就很坚信这个结论了.队列这种东西,最广泛的作用还是在于解耦,宽泛一点的说,它可以将不同部门的工作内容进行有效的整合,基于一个约定 ...

  9. 树莓派无显示屏连接wifi

    在烧好Raspbian系统的TF卡boot分区新建 wpa_supplicant.conf 文件,内容如下(修改自己的WIFI名和密码,key_mgmt根据路由器配置),保存后启动树莓派即可自动连接W ...

  10. Kotlin匿名函数与闭包详解

    Lambda表达式实例演练: 继续先来编写一些Lambda表达式相关的代码: 接下来想从上面的字符串数组中找到带有"h"的字符串并打印出来: 如果学习了Java8的Lambda表达 ...