zoukankan      html  css  js  c++  java
  • ZOJ Problem Set–1514 Fake Tickets

    Time Limit: 2 Seconds      Memory Limit: 65536 KB


    Your school organized a big party to celebrate your team brilliant win in the prestigious, worldfamous ICPC (International Collegiate Poetry Contest). Everyone in your school was invited for an evening which included cocktail, dinner and a session where your team work was read to the audience. The evening was a success - many more people than you expected showed interested in your poetry - although some critics of yours said it was food rather than words that attracted such an audience.
    Whatever the reason, the next day you found out why the school hall had seemed so full: the school director confided he had discovered that several of the tickets used by the guests were fake. The real tickets were numbered sequentially from 1 to N (N <= 10000). The director suspects some people had used the school scanner and printer from the Computer Room to produce copies of the real tickets. The director gave you a pack with all tickets collected from the guests at the party's entrance, and asked you to determine how many tickets in the pack had 'clones', that is, another ticket with the same sequence number.

    Input
    The input contains data for several test cases. Each test case has two lines. The first line contains two integers N and M which indicate respectively the number of original tickets and the number of persons attending the party (1 <= N <= 10000 and 1 <= M <= 20000). The second line of a test case contains M integers Ti representing the ticket numbers in the pack the director gave you (1 <= Ti <= N). The end of input is indicated by N = M = 0.

    Output
    For each test case your program should print one line, containing the number of tickets in the pack that had another ticket with the same sequence number.

    Sample Input

    5 5
    3 3 1 2 4
    6 10
    6 1 3 6 6 4 2 3 1 2
    0 0

    Sample Output

    1
    4


    Source: South America 2002, Practice

    题目要计算的是有多少票被复制了,而不是假票的数量!

    #include<iostream>
    
    #include<set>
    
    using namespace std;
    
    int main()
    
    {
    
      int n,m;
    
      while(cin>>n>>m && (n || m))
    
      {
    
        int tickets;
    
        set<int> s,s0;
    
        while(m-- && cin>>tickets)
    
        {
    
          if(s.find(tickets) != s.end())
    
            s0.insert(tickets);
    
          else
    
            s.insert(tickets);
    
        }
    
        cout<<s0.size()<<endl;
    
      }
    
      return 0;
    
    }
  • 相关阅读:
    atitit.解决struts2 SpringObjectFactory.getClassInstance NullPointerException
    atitit。 hb Hibernate sql 查询使用
    atitit.插件体系设计总结o73.doc
    Atitit.可视化编程jbpm6 的环境and 使用总结...
    paip.自动import的实现跟java.lang.SecurityException Prohibited package name java
    Linux下tar.xz结尾的文件的解压方法
    ubuntu下的Samba配置:使每个用户可以用自己的用户名和密码登录自己的home目录
    ubuntu Linux离线安装软件包
    C语言文件操作解析(一)[转载]
    PDF XChange Viewer文件关联
  • 原文地址:https://www.cnblogs.com/malloc/p/2427384.html
Copyright © 2011-2022 走看看