Coder-Strike 2014 - Finals (online edition, Div. 2) C题

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= 100010;
 8  char cha[MAX];
 9  int num[MAX];
10  int ans[MAX];
11  set< int>s;
12  set< int>alone;
13  int main()
14 {
15      int n,m;
16      while(cin>>n>>m)
17     {
18         memset(cha, 0, sizeof(cha));
19         memset(num, 0, sizeof(num));
20         memset(ans, 0, sizeof(ans));
21         s.clear();
22         alone.clear();
23          for( int i= 1;i<=m;i++)
24         cin>>cha[i]>>num[i];
25          for( int i= 1;i<=m;i++)
26         {
27              if(cha[i]== ' - ')
28             {
29                  if(ans[num[i]]== 0)
30                 {
31                     s.insert(num[i]);
32                 }
33             }
34             ans[num[i]]= 1;
35         }
36         memset(ans, 0, sizeof(ans));
37          for( int i= 1;i<=m;i++)
38         {
39              if(cha[i]== ' + ')
40             {
41                 s.insert(num[i]);
42                  if(s.size()> 1)
43                 ans[num[i]]= 1;
44                  else alone.insert(num[i]);
45             }
46              else
47             {
48                 s.erase(num[i]);
49                  if(s.size()> 0)
50                 ans[num[i]]= 1;
51                  else alone.insert(num[i]);
52             }
53         }
54          if(alone.size()!= 1)
55         {
56              for( set< int>::iterator p=alone.begin();p!=alone.end();p++)
57             {
58                 ans[*p]= 1;
59             }
60         }
61         vector< int>ANS;
62          for( int i= 1;i<=n;i++)
63         {
64              if(ans[i]== 0)
65             ANS.push_back(i);
66         }
67         cout<<ANS.size()<<endl;
68          if(ANS.size()!= 0)
69         {
70              for( int i= 0;i<ANS.size()- 1;i++)
71             cout<<ANS[i]<< '   ';
72             cout<<ANS[ANS.size()- 1]<<endl;
73         }
74     }

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

 

转载于:https://www.cnblogs.com/forgot93/p/3684284.html

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、下4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、下4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值