C. Online Meeting
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts shared online meetings in a Spyke chat.

One day the director of the F company got hold of the records of a part of an online meeting of one successful team. The director watched the record and wanted to talk to the team leader. But how can he tell who the leader is? The director logically supposed that the leader is the person who is present at any conversation during a chat meeting. In other words, if at some moment of time at least one person is present on the meeting, then the leader is present on the meeting.

You are the assistant director. Given the 'user logged on'/'user logged off' messages of the meeting in the chronological order, help the director determine who can be the leader. Note that the director has the record of only a continuous part of the meeting (probably, it's not the whole meeting).

Input

The first line contains integers n and m (1 ≤ n, m ≤ 105) — the number of team participants and the number of messages. Each of the next m lines contains a message in the format:

  • '+ id': the record means that the person with number id (1 ≤ id ≤ n) has logged on to the meeting.
  • '- id': the record means that the person with number id (1 ≤ id ≤ n) has logged off from the meeting.

Assume that all the people of the team are numbered from 1 to n and the messages are given in the chronological order. It is guaranteed that the given sequence is the correct record of a continuous part of the meeting. It is guaranteed that no two log on/log off events occurred simultaneously.

Output

In the first line print integer k (0 ≤ k ≤ n) — how many people can be leaders. In the next line, print k integers in the increasing order — the numbers of the people who can be leaders.

If the data is such that no member of the team can be a leader, print a single number 0.

Sample test(s)
input
5 4
+ 1
+ 2
- 2
- 1
output
4
1 3 4 5
input
3 2
+ 1
- 2
output
1
3
input
2 4
+ 1
- 1
+ 2
- 2
output
0
input
5 6
+ 1
- 1
- 3
+ 3
+ 4
- 4
output
3
2 3 5
input
2 4
+ 1
- 2
+ 2
- 1
output
0

还是不会这种模拟题,看来模拟题是我的软肋!先贴别人的题解:http://blog.csdn.net/cc_again/article/details/24368265

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<set>
 5 #include<vector>
 6 using namespace std;
 7 const int MAX=;
 8 char cha[MAX];
 9 int num[MAX];
 int ans[MAX];
 set<int>s;
 set<int>alone;
 int main()
 {
     int n,m;
     while(cin>>n>>m)
     {
         memset(cha,,sizeof(cha));
         memset(num,,sizeof(num));
         memset(ans,,sizeof(ans));
         s.clear();
         alone.clear();
         for(int i=;i<=m;i++)
         cin>>cha[i]>>num[i];
         for(int i=;i<=m;i++)
         {
             if(cha[i]=='-')
             {
                 if(ans[num[i]]==)
                 {
                     s.insert(num[i]);
                 }
             }
             ans[num[i]]=;
         }
         memset(ans,,sizeof(ans));
         for(int i=;i<=m;i++)
         {
             if(cha[i]=='+')
             {
                 s.insert(num[i]);
                 if(s.size()>)
                 ans[num[i]]=;
                 else alone.insert(num[i]);
             }
             else
             {
                 s.erase(num[i]);
                 if(s.size()>)
                 ans[num[i]]=;
                 else alone.insert(num[i]);
             }
         }
         if(alone.size()!=)
         {
             for(set<int>::iterator p=alone.begin();p!=alone.end();p++)
             {
                 ans[*p]=;
             }
         }
         vector<int>ANS;
         for(int i=;i<=n;i++)
         {
             if(ans[i]==)
             ANS.push_back(i);
         }
         cout<<ANS.size()<<endl;
         if(ANS.size()!=)
         {
             for(int i=;i<ANS.size()-;i++)
             cout<<ANS[i]<<' ';
             cout<<ANS[ANS.size()-]<<endl;
         }
     }

75 }一种网上很好的代码风格

Coder-Strike 2014 - Finals (online edition, Div. 2) C题的更多相关文章

  1. Coder-Strike 2014 - Finals (online edition, Div. 2) A. Pasha and Hamsters

    水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...

  2. Coder-Strike 2014 - Finals (online edition, Div. 2) B. Start Up

    需要满足的条件是 (1)每个字母是对称的 (2)每个字符串是对称的 #include <iostream> #include <algorithm> #include < ...

  3. Coder-Strike 2014 - Finals (online edition, Div. 1)

    CF 420A  A. Start Up 题目链接: http://codeforces.com/problemset/problem/420/A 题目意思: 给一个字符串A,通过镜面反射后得到A', ...

  4. Bubble Cup 11 - Finals [Online Mirror, Div. 1]题解 【待补】

    Bubble Cup 11 - Finals [Online Mirror, Div. 1] 一场很好玩的题啊! I. Palindrome Pairs 枚举哪种字符出现奇数次. G. AI robo ...

  5. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  6. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  7. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  8. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) B. Bear and Compressing

    B. Bear and Compressing 题目链接  Problem - B - Codeforces   Limak is a little polar bear. Polar bears h ...

  9. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表

    E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #inclu ...

随机推荐

  1. C# 平时碰见的问题【6】

    EF Code First 设置复合主键的方法 除了单纯多对多的关系表外, 我们可能在关系表上加其他的属性: 比如[订单行] 对应的[订单]和[商品]就需要多一个数量字段 而又不想在这个[订单行]表上 ...

  2. 【微网站开发】之微信内置浏览器API使用

    最近在写微网站,发现了微信内置浏览器的很多不称心的地方: 1.安卓版的微信内浏览器底部总是出现一个刷新.前进.后退的底部栏,宽度很大,导致屏幕显示尺寸被压缩 2.分享当前网站至朋友圈时,分享的图片一般 ...

  3. 菜鸟学习Hibernate——缓存

    Hibernate的缓存分为三种:一级缓存.二级缓存.查询缓存.下面我就为大家介绍一下. 一.概念. 一级缓存:第一级存放于session中称为一级缓存.Session 级别的缓存,它同session ...

  4. JSAPI_Ticket签名

    1.微信 JS 接口签名校验工具 2.具体开发 2.1 获取access_token,然后jsapi_ticket /** * 获取access_token,然后jsapi_ticket */ pri ...

  5. ORA-08189

    OS: [root@yoon ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 DB: Oracle Database 11g E ...

  6. arcgis中使用excel中x,y坐标创建点问题

    文件——从x,y中添加,可以显示点的位置 右击图层导出数据时,出现无法绘制图形,生成shapefile文件的情况.经过排除数据发现 当x,y坐标值中出现null等异常值时,会出现上述无法导出的情况.

  7. Hadoop之Hive自定义函数的陷阱

    A left join B, 这个B会连到A. 如<A1,B>, <A2,B>,在处理第一条记录的时候将B.clear(),则第二条记录的B是[]空的这是自定义UDF函数必须注 ...

  8. Java之蛋疼的file Protocol

    file Protocol Opens a file on a local or network drive. Syntax file:///sDrives[|sFile] Tokens sDrive ...

  9. 条款10:令operator=返回一个*this的引用

    为了编程的简洁性,有时候需要串联赋值,如:x = y = z = 15; 由于赋值采用右结合,因此上述语句被解释为:x = (y = (z = 15)); 为了实现串联赋值,复制操作符函数必须返回一个 ...

  10. 设置浮点数的显示精度&precision(0)

    /*    设置浮点数的显示精度    cout.precision(int)可以设置浮点数的显示精度(不包括小数点)        注: 1.如果设置的精度大于浮点数的位数,如果浮点数能根据IEEE ...