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

  • 员工每天最多只能进入一次办公室
  • 如果那天他没有进办公室的话,他显然不能离开
  • 每天开始和结束时,办公室都是空的(员工不能呆在晚上),办公室也可能在一天中的任何时候都是空的

现在给你序列$a$($a[i] \neq 0$),问你是否能够把数组$a$分为几个相邻的子数组,使得每一个子数组员工的进出情况符合要求并输出每一个子数组的长度,或者输出$-1$表示不可能

思路:用一个数组$mk$标记某个人状态,$mk[i]=0$表示$i$号员工在这一天内还没有操作,$mk[i]=1$表示$i$号员工在这一天内已经进入办公室,$mk[i]=-1$表示$i$号员工在这一天内已经进入办公室并且出去了,$num$记录此时办公室的人数,如果$num=0$时则可以进入新的一天,同时需要用一个数组$p$记录这一天已经出去的员工编号,在进入新的一天时,则需要将这些员工的$mk[i]$变为$0$,中间出现不合法的情况直接跳出循环,输出$-1$

#include <iostream>
#include <algorithm>
#include <cstdio> using namespace std; const int N = ;
const int M = ; int n, a[N], mk[M];
int num, cnt, p[N];
int res[N], pos; int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
int flag = ; res[++pos] = ;
for (int i = ; i <= n; i++) {
if (a[i] > ) {
if ( == mk[a[i]]) {
mk[a[i]] = , num++;
}
else {
flag = ; break;
}
}
else {
if ( == mk[-a[i]]) {
mk[-a[i]] = -, num--;
p[++cnt] = -a[i];
if ( == num) {
for (int j = ; j <= cnt; j++) mk[p[j]] = ;
cnt = , res[++pos] = i;
}
}
else {
flag = ; break;
}
}
}
if ( != num) flag = ;
if (!flag) printf("-1\n");
else {
printf("%d\n", pos - );
for (int i = ; i <= pos; i++) {
printf("%d", res[i] - res[i - ]);
printf(i == pos ? "\n" : " ");
}
}
return ;
}

Codeforces Round #600 (Div. 2) - B. Silly Mistake(模拟)的更多相关文章

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

    #include<iostream> #include<map> #include<set> #include<algorithm> using nam ...

  2. 【cf比赛记录】Codeforces Round #600 (Div. 2)

    Codeforces Round #600 (Div. 2) ---- 比赛传送门 昨晚成绩还好,AC A,B题,还能上分(到底有多菜) 补了C.D题,因为昨晚对C.D题已经有想法了,所以补起题来也快 ...

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

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

  4. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

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

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

  6. Codeforces Round #600 (Div. 2)

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

  7. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

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

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

随机推荐

  1. AC3 mantissa quantization and decoding

    1.overview 所有的mantissa被quantize到固定精确度的level(有相应的bap标识)上,level小于等于15时,使用symmetric quantization.level大 ...

  2. pycharm2019.3安装以及激活

    最近很多的pycharm激活过期的,小伙伴们问我pycharm要怎么激活?这里就分享一下pycharm最新版本的安装以及激活吧!!! 首先先去官网(https://www.jetbrains.com/ ...

  3. 题解 P5594 【【XR-4】模拟赛】

    P5594 [[XR-4]模拟赛] 洛谷10月月赛 II & X Round 4 Div.2前两道签到题还是很简单的,基本上是半小时内一遍过两题 看看题解,这题STL做法有用set输出size ...

  4. The entity type XXX is not part of the model for the current context.

    今天遇到了一个奇葩问题,虽然解决了,但还是一脸懵,先附赠一下别人的解决方案:https://www.cnblogs.com/zwjaaron/archive/2012/06/08/2541430.ht ...

  5. 一些常用的js代码

    跳转 window.location.href= 刷新  location.reload()

  6. POJ2909_Goldbach's Conjecture(线性欧拉筛)

    Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one p ...

  7. 「题解」「UOJ-164」「清华集训2015」V

    目录 题目 原题目 简要题目 正解 这道题题目简洁新颖,吸引读者阅读兴趣... 题目 原题目 点这里 简要题目 需要你维护长度为n的序列并支持下列操作: 区间加法: 区间赋值: 区间每个 \(a_i\ ...

  8. 1.4 Eclipse 自动补全功能

    1.访问Content Assit 菜单项  window--preferences --Java---Editor--Content Assit 2. auto activation delay : ...

  9. vue项目怎么搭建到云服务器上

    链接1:https://blog.csdn.net/qq_37741554/article/details/87560823 linux下载安装node.js 链接2:https://blog.csd ...

  10. bootstrap fileinput上传文件

    参考博客:https://blog.csdn.net/linhaiyun_ytdx/article/details/76215974  https://www.cnblogs.com/parker-y ...