Simulation [NOIP2007] Statistics

Source: Internet
Author: User
Tags time limit
NOIP2007 Statistics

Time limit: 1 Sec memory limit: Ten MB the topic describes a scientific investigation when the N natural number is obtained, each number is not more than 1500000000 (1.5*109). There are no more than 10,000 known numbers, and it is now necessary to count the number of occurrences of these natural numbers, and to output the statistical results in the order of natural numbers from small to large. The first line of input is an integer n, which indicates the number of natural numbers;
Section 2~n+1 a natural number per line. The output contains m rows (m is the number of different numbers in N natural numbers), and is output in order from small to large in natural numbers. Each row outputs two integers, each of which is the natural number and the number of occurrences, separated by a space. Sample Input 8
Sample Output 2 3
4 2
5 1
2 hint 40% data to meet: 1<=n<=1000
80% of the data meet: 1<=n<=50000
100% data satisfies: 1<=n<=200000, each number is not more than 1500 000 000 (1.5*109)

var w:array[1..200000]of longint;
Procedure sort (l,r:longint);
var i,j,x,y,c:longint; Begin I:=l; J:=r;
 x:=w[(l+r) Div 2];
  Repeat while W[i]<x do Inc (i);
  While X<w[j] do Dec (j); If not (I>J) then begin c:=w[i]; W[I]:=W[J];
    W[j]:=c; Inc (I);
   Dec (j);
 Until i>j;
 If L<j then sort (l,j);
If I<r then sort (i,r);
 Begin READLN (n);
 For I:=1 to N do readln (W[i]);
 Sort (1,n);
   While Ci<=n does begin sum:=0;
    For J:=CI to n does begin if W[J]=W[CI] then Inc. (sum) else break;
   Writeln (W[ci], ", sum);
  Inc (Ci,sum);
End End. 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.