codeforces 420B Online Meeting
一道实现很蛋疼的题。必须静下理清思路,整理出各种情况。不然就会痛苦地陷入一大堆if..else里不能自拔。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb(a) push(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI 3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c) {
return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c) {
return max(max(a,b),max(a,c));
}
void debug() {
#ifdef ONLINE_JUDGE
#else freopen("in.txt","r",stdin);
freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch() {
int ch;
while((ch=getchar())!=EOF) {
if(ch!=' '&&ch!='\n')return ch;
}
return EOF;
} const int maxn = 1e5+;
bool canbe[maxn];
int canbeset[maxn];
int first[maxn];
char op[maxn];
int id[maxn];
int main()
{
int n,m;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++ )
{
op[i] = getch();
scanf("%d", &id[i]);
if( first[id[i]] == )
first[id[i]] = op[i] == '+' ? : -; }
int cnt=;
int sz=;
for(int i=;i<=n;i++)
{
if(first[i]==-)
cnt++;
if(first[i]==)
canbeset[sz++]=i;
} for(int i=;i<=n;i++) canbe[i] = true;
if(cnt>) for(int i=;i<=n;i++)
if(first[i]==) canbe[canbeset[--sz]] = false; for(int i=;i<=m;i++)
{
if(op[i]=='+')
{
if(cnt>) canbe[id[i]]=;
cnt++;
while(sz)
{
sz--;
if(canbeset[sz]!=id[i]) canbe[canbeset[sz]]=;
}
}else
{
cnt--;
if(cnt>) canbe[id[i]]=;
if(canbe[id[i]]) canbeset[sz++]=id[i];
}
}
sz=;
for(int i=;i<=n;i++)
if(canbe[i])
canbeset[sz++]=i;
printf("%d\n",sz);
for(int i=;i<sz;i++)
printf("%d%c",canbeset[i],i==sz-?'\n':' '); return ;
}
codeforces 420B Online Meeting的更多相关文章
- Online Meeting CodeForces - 420B (思维)
大意: 给定某一段连续的上线下线记录, 老板上线或下线时房间无人, 并且每次会议都在场, 求哪些人可能是老板. 结论1: 从未出现过的人一定可以是老板. 结论2: 出现过的人中老板最多只有1个. 结论 ...
- codeforces 782B The Meeting Place Cannot Be Changed (三分)
The Meeting Place Cannot Be Changed Problem Description The main road in Bytecity is a straight line ...
- Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)
题目链接 The Meeting Place Cannot Be Changed 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...
- CF - 420B - Online Meeting(思维)
题意:n 个人參加线上会议.某经理记录了中间一段时间的 m 条上下线记录(1 ≤ n, m ≤ 105).+ 表示上线,- 表示下线. leader是指仅仅要有人在线,他都在线的人.求全部可能的lea ...
- codeforces B. Online Meeting 解题报告
题目链接:http://codeforces.com/problemset/problem/420/B 题目意思:给出一段连续的消息记录:记录着哪些人上线或者下线.问通过给出的序列,找出可能为lead ...
- codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)
B. The Meeting Place Cannot Be Change ...
- Codeforces 853B Jury Meeting (差分+前缀和)
<题目链接> 题目大意: 有$ n(n<=1e5)$个城市和一个首都(0号城市),现在每个城市有一个人,总共有$ m (m<=1e5)$次航班,每个航班要么从首都起飞,要么飞到 ...
- codeforces 782B - The Meeting Place Cannot Be Changed
time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standa ...
- codeforces 853b//Jury Meeting// Codeforces Round #433 (Div. 1)
题意:几个人要去一个城市k天,现给出各航班的日期和花费,让这n个人能相会k天的最小花费? 用数组arr1[i]记录在第i天人到齐的最小花费.arr2[i]记录第i天之后才有人开始走的最小花费.然后取a ...
随机推荐
- Gson处理
public class GsonTools { public GsonTools(){} public static <T> T getPerson(String jsonString, ...
- Android OpenCV 图像识别
最近打算写一个android 平台opencv 的小程序,着手查找了一下资料.网络上的资料参差不齐,有一些都比较老旧,我参考了前面的方法找到了一个简单的搭建方法,分享给大家. 0,环境的搭建: jav ...
- Eclipse编辑XML文件的代码提示
1.Eclipse无法解析的情形 Eclipse中编辑XML文件时,能够代码自动提示,是因为在XML头部引入了DTD文件(文档类型定义),Eclipse就是通过解析这个DTD文件,来达到代码提示的功能 ...
- mysql数据库优化小结
一.常见数据库的优化操作 1.表的设计要符合三范式. 2.添加适当的索引,索引对查询速度影响很大,必须添加索引.主键索引,唯一索引,普通索引,全文索引 3.添加适当存储过程,触发器,事务等. 4.读写 ...
- 编译错误:error: multi-line comment
编译错误:error: multi-line comment 这其实是有宏定义的地方的问题. 原因是宏定义非一行,在宏定义的行尾使用 '\' 连接符导致的. 所以这个地方的注释使用 /* */ ...
- 用file上传文件时,浏览器返回值总是自动添加<pre>的解决办法
在返回的JSon字符串里面总是莫名其妙的添加了<pre>标签,例如返回内容为"ok",在浏览器里面就变成了"<pre style="word- ...
- (转载)SQL Server 2005 如何启用xp_cmdshell组件
原文地址:http://www.cnblogs.com/atree/p/SQL_SERVER_xp_cmdshell.html [错误描述]: SQL Server阻止了对组件‘xp_cmdshell ...
- Esfog_UnityShader教程_镜面反射SpecularReflection
系列教程第四篇,本来打算昨天写的,有些小偷懒就今天写了,这一期我们来讨论一下关于镜面反射的基本原理和具体代码.这一篇是承接着上一篇<Esfog_UnityShader教程_漫反射DiffuseR ...
- ubuntu下基于sqlite3后台的php环境的搭建
最近准备把公司的服务器换成linux 数据库sqlite3 搭建过程记录如下: 1 sqlite3安装.. apt-get install sqlite 2.PHP服务器搭建. apt-get ins ...
- Android Studio JNI/NDK 编程简介(一)
首先说一下概念及相关的东西: JNI : JNI是Java Native Interface的缩写,它提供了若干的API实现了Java和其他语言的通信(主要是C&C++).从Java1.1开始 ...