Luogu1059 obviously random number

STL is a good thing!

See this question, of course I thought of the heap; there is something called a priority queue priority_queue in the STL (in fact, a more appropriate set of solving the problem) , and then open a barrel to see this number is not already there, you have hold in, not just thrown in; perfect; return 0;
put the following code

#include <bits / STDC ++ H.> 
#include <Queue>   // add this header code in the code a lot easier when 
the using  namespace STD;
 BOOL B [ 2000 ]; // is a tub 
int n-; 
The priority_queue < int , Vector < int >, greater < int >> Data;
 // int type is, vector is a container, greater root small stack 
int main () 
{ 
//     The freopen ( "testdata.in", "R & lt", stdin); / / test ignored like with 
    
    CIN >> n-;
     int X;
     for ( int I =. 1 ; I <= n-; I ++ ) 
    { 
        CIN >> X;
         IF ! ( B [X]) 
        { 
            data.push (X); 
            B [X] = to true ; // input through the digital input is not the next 
        } 
    } 
    COUT << data.size () << endl; // returns the number of elements 
    int K = data.size (); // here must be recorded at, or below when the operation .size () returns the value change on the bad 
    for ( int I = . 1 ; I <= K; I ++ ) 
    { 
        COUT << data.top () << '  ' ; 
        data.pop ();// pop uppermost element 
        
    } 
    return  0 ; 
}

就是 这样! Yes 什么 problem hope landlord ability Sashide! Thank you very much.

Guess you like

Origin www.cnblogs.com/Shiina-Rikka/p/11223647.html