ZOJ 1514 解题报告

Fake Tickets

Time Limit: 1 Seconds Memory Limit: 32768 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

Output for Sample Input

1
4

题目的意思很简单,给出一堆门票的号码,算出有多少张票被伪造过.多次被伪造只算一次.

CODE

#include<stdio.h>
#include<string.h>
 
int main()
{
  int D[10005];
  int i,j,k;
  int n,m;
  while(scanf("%d%d",&n,&m)!=EOF,!(n==0&&m==0))
    {
      memset(D,0,sizeof(D));
      int cnt=0;
      for(i=0;i<m;++i)
        {
          scanf("%d",&k);
          ++D[k];
          if(D[k]==2) ++cnt;
        }
      printf("%d\n",cnt);
    }
  return 0;
}
» 本博客采用署名 2.5 中国大陆许可协议进行许可,本文版权归作者所有,欢迎转载,但必须在明显位置给出原文连接。
anyShare分享到:

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>