Hdoj 1800 HDU 1800 phone list ACM 1800 in HDU

Source: Internet
Author: User

Miyu original, post Please note: Reprinted from __________ White House

 

Question address:

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1800

Description:

Problem description
In the year 8888, the Earth is ruled by the PPF empire. as the population growing, PPF needs to find more land for the newborns. finally, PPF decides to attack kscinow who ruling the Mars. here the problem comes! How can the soldiers reach the Mars? PPF convokes his soldiers and asks for their suggestions. "rush... "One soldier answers." Shut up! Do I have to remind you that there isn't any road to the Mars from here !" PPF replies. "fly !" Another answers. PPF smiles: "clever guy! Although we haven'tgot wings, I can buy some magic broomsticks from Harry Potter to help you. "Now, it's time to learn to fly on a broomstick! We assume that one soldier has one level number indicating his degree. the soldier who has a higher level cocould teach the lower, that is to say the former's level> the latter's. but the lower can't teach the higher. one soldier can have only one teacher at most, certainly, having no teacher is also legal. similarly one soldier can have only one student at most while having no student is also Possible. Teacher can teach his student on the same broomstick. Certainly, all the soldier must have practiced on the broomstick before they fly to the Mars! Magic broomstick is expensive! So, can you help PPF to calculate the minimum number of the broomstick needed.
For example:
There are 5 soldiers (a B c d e) with level numbers: 2 4 5 6 4;
One method:
C cocould teach B; B cocould teach a; so, a B C are eligible to study on the same broomstick.
D cocould teach E; so d e are eligible to study on the same broomstick;
Using this method, we need 2 broomsticks.
Another method:
D coshould teach a; so a D are eligible to study on the same broomstick.
C cocould teach B; so B C are eligible to study on the same broomstick.
E with no teacher or student are eligible to Study on One Broomstick.
Using the method, we need 3 broomsticks.
......

After checking up all possible method, we found that 2 is the minimum number of broomsticks needed.

Inputinput file contains multiple test cases.
In a test case, the first line contains a single positive number N indicating the number of soldiers. (0 <= n <= 3000)
Next n lines: there is only one nonnegative integer on each line, indicating the level number for each soldier. (less than 30 digits );

Outputfor each case, output the minimum number of broomsticks on a single line.

Sample Input

 
410203004523434

Sample output

 
12

Question Analysis:

 

The efficiency of using the dictionary tree is relatively higher ..... unfortunately, I will only do some questions about the dictionary tree .... the understanding of the dictionary tree is not very good now ...... so, huh, huh

I have filtered this question directly ........

 

CodeAs follows:

/*

Miyu original, post Please note: Reprinted from __________ White House

Http://www.cnblog.com/MiYu

Author by: miyu

Test: 1

Program: 1800

*/

# Include <iostream>

# Include <algorithm>

Using namespace STD;

Int num [3002];

Bool hash [3002];

Bool CMP (const Int & A, const Int & B)

{

Return A> B;

}

Int main ()

{

Int N;

While (scanf ("% d", & N )! = EOF)

{

Memset (Num, 0, 12008 );

Memset (hash, 0, 3002 );

For (INT I = 0; I! = N; ++ I)

Scanf ("% d", num + I );

Sort (Num, num + N, CMP );

Int ncount = 0;

For (INT I = 0; I <n; ++ I)

{

If (! Hash [I])

{

Ncount ++;

Int J = I, K = J + 1;

Hash [J] = true;

While (k <n)

{

If (! Hash [k] & num [k] <num [J])

{

Hash [k] = true;

J = K;

}

K ++;

}

}

}

Printf ("% d \ n", ncount );

}

Return 0;

}

 

 

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: info-contact@alibabacloud.com 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.