• 登入 退出


    题目网址: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102145#problem/D

    Description

    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 Input

    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

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    const int maxn=1e5+5;
    int f[maxn],g[maxn];
    int d[maxn];
    char c[maxn];
    
    int main()
    {
        int n,m,num;
        while(cin>>n>>m)
        {
            memset(f,0,sizeof(f));
            memset(g,0,sizeof(g));
            num=0;
            for(int i=0; i<m; i++)
            {
                cin>>c[i]>>d[i];
                if(c[i]=='-'&&!f[d[i]])
                num++;
                f[d[i]]=1;
            }
            for(int i=0; i<m; i++)
            {
                if(c[i]=='+')
                {
                    if((i>=1&&d[i-1]!=d[i])||num)
                    g[d[i]]=1;
                    num++;
                }
                else
                {
                    num--;
                    if((i<=m-2&&d[i+1]!=d[i])||num)
                    g[d[i]]=1;
                }
            }
            int ans=0;
            for(int i=1; i<=n; i++)
             if(!g[i])
             ans++;
            printf("%d
    ",ans);
            for(int i=1; i<=n; i++)
            if(!g[i])
            printf("%d ",i);
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    git的操作流程命令步骤 软件测试媛
    IT相关的编程技术类学习网站整理 软件测试媛
    Linux中的centos下使用docker搭建gitlab步骤 软件测试媛
    Windows下安装MSI格式的MySQL8.0,且使用自定义配置安装步骤 软件测试媛
    MySQL远程连接工具之Navicat Premium下载及安装步骤 软件测试媛
    截止2021年底,我国18个税种中已有12个税种完成立法
    国产银河麒麟Kylin V10操作系统如何把常用文件夹加入左侧侧边栏(类似windows文件资源管理器中的收藏夹)
    消费税
    做任何事(决策)之前都要先考虑成本,再考虑收益
    具名组匹配(ES9)更改时间格式
  • 原文地址:https://www.cnblogs.com/chen9510/p/5040257.html
Copyright © 2020-2023  润新知