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. windows中Crontab的使用

    一.jdk的安装 安装地址ttps://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 二 . ...

  2. 2017-07-26 ThinkPHP简单使用

    ThinkPHP是什么?有何优点? ThinkPHP 是一个免费开源的,快速.简单的面向对象的 轻量级PHP开发框架,ThinkPHP为WEB应用开发提供了强有力的支持,这些支持包括: * MVC支持 ...

  3. iframe中操作主体页面的元素,方法

    在不使用三大框架的情况下,iframe的使用可以做到在页面中直接引入别的页面作为当前页面的一部分,但是在iframe的使用过程中存在一些相互之间的操作 例如在iframe中获取主页面的元素,使用主页面 ...

  4. Vue学习之路由vue-router传参及嵌套小结(十)

    一.路由传递参数: 1.使用query传值: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  5. Keras上实现简单线性回归模型

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/marsjhao/article/detai ...

  6. Docker以http访问Harbor私有仓库(一)

    1 说明 前文Centos7搭建Harbor私有仓库(一)我们成功搭建Harbor,本篇我们主要配置Docker以http方式访问私有仓库 2 Docker配置 2.1 Mac系统 2.1.1 配置D ...

  7. Linux系统禁止root账号远程登录

    修改配置文件/etc/ssh/sshd_config,去掉PermitRootLogin前的注释,修改值为no,然后重启sshd服务即可 #LoginGraceTime 2m PermitRootLo ...

  8. java项目路径总结,java.io.File支持的路放方式

    1.直接输入路径 已maven项目为例,直接输入路径的4种方式,即是File类支持的方式: /** * FileOutpurStream以字节数组方式写入文件 * @throws IOExceptio ...

  9. 【Netty】Netty的Hello World程序之Discard Server

    一.有关Discard Server的说明 世界上最简单的协议(程序)不是“Hello, World!”而是Discard(丢弃).它是一种丢弃任何接收到的数据而没有任何响应的协议. 要实现丢弃协议, ...

  10. 树莓派3b+更改静态IP

    ubuntu系统修改静态IP的方法是在修改/etc/network/interfaces文件,而树莓派此文件下有说明: # interfaces() ) and ifdown() # Please n ...