HDU-1800-flying to the Mars

Source: Internet
Author: User
Flying to the Mars

Time Limit: 5000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 8319 accepted submission (s): 2692

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' t got
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
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

 

Code:

 

 
# Include "cstdio" # include "cstring" # include "algorithm" using namespace STD; int main () {int N, level [3001], sign [3001]; int t, i, j, num = 0, temp; while (scanf ("% d", & N )! = EOF) {num = 0; memset (sign, 1, sizeof (sign); // The Position of the flag is 1, and the position of a broom is 0 for (I = 1; I <= N; I ++) scanf ("% d", & level [I]); sort (LEVEL + 1, LEVEL + n + 1 ); // sort for (I = 1; I <= N; I ++) {If (sign [I]) // compare objects without a broom {sign [I] = 0; temp = level [I]; for (j = I; j <= N; j ++) // from the current bit to the end, locate all numbers greater than this bit and set them to 0 {If (sign [J]) if (level [J]> temp) {temp = level [J]; sign [J] = 0 ;}} num ++; // broom ++} printf ("% d \ n ", num );}}

 

 

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.