题意:有一个公司,每天有员工进出,$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. 问题总结:mysql和javaweb工程连接的过程中容易产生的问题

    问题背景:自己在本机的mysql8瘫痪了,将Oracle中的数据迁移到mysql之后,配置好javaweb工程和虚拟机上的远程Mysql连接的文件之后:遇见了无法访问的问题 具体的配置: dataso ...

  2. Vue-移动端开发全家桶

    内容:node.js,vue-cli,vuex,axios,postcss-pxtorem,lib-flexible,vant ,babel-plugin-import 1.安装脚手架工具: npm ...

  3. Python 数据分析实战 | 用数据带你回顾乔丹的职业生涯

    乔丹是联盟上下公认的历史第一人,芝加哥公牛在他带领下几乎统治了上世纪 90 年代 NBA 整整 10 年,包括分别在 91-93 赛季和 96-98 赛季拿下的两次三连冠,要知道,NBA72 年历史上 ...

  4. mongo日常命令集锦

    查询某个字段是否存在 db.student.findOne({name:{$exists:true}}) db.student.findOne({'department.name':{$exists: ...

  5. RMQ入门解析

    参照大佬博客:https://www.cnblogs.com/yoke/p/6949838.html RMQ(Range Minimum/Maximum Query),  是一种问题,即 查询给定区间 ...

  6. 每天进步一点点------DE2-70-TV例子说明

    module Reset_Delay(iCLK,iRST,oRST_0,oRST_1,oRST_2); input iCLK; input iRST; output reg oRST_0; outpu ...

  7. 自己centos7成功的修改了主机名(记录了该改哪些文件)

    1.更改/etc/hosts 方法(1)可以直接的去更改这个文件,更改的格式:直接vi编辑器打开,之后直接写上自己想要的主机名字就好,不用写成键值对的形式 [root@localhost etc]# ...

  8. pwnable.kr-bof-Writeup

    MarkdownPad Document *:first-child { margin-top: 0 !important; } body>*:last-child { margin-botto ...

  9. UITextField的内存泄漏问题

    背景: 项目中使用了Facebook的FBRetainCycleDetector框架检测内存泄漏问题. 登录VC的view中放置了一个UITextField对象. 产品的要求是当进入登录界面的时候,让 ...

  10. PAT 1013 Battle Over Cities (dfs求连通分量)

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...