HDU 1800 Flying to the Mars

Source: Internet
Author: User

Problem Description
The year 8888, the Earth was 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 has to remind your 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-fly on a broomstick! We assume that one soldier have one level number indicating his degree. The soldier who have a higher level could teach the lower, that's to say the former's level > the latter ' s. But the lower can ' t teach the higher. One soldier can has only one teacher at the most, certainly, has no teacher is also legal. Similarly one soldier can has only one StUdent at the most and have no student is also possible. Teacher can teach his student on the same broomstick. Certainly, all the soldier must has 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 is 5 soldiers (A B C D E) with level Numbers:2 4 5 6 4;
One method:
C could teach B; B could teach A; So, A B C is eligible to study on the same broomstick.
D could teach E; So D E is eligible to study on the same broomstick;
Using This method, we need 2 broomsticks.
Another method:
D could teach A; So A D is eligible to study on the same broomstick.
C could teach B; So B C is eligible to study on the same broomstick.
E with no teacher or student is eligible to study on one broomstick.
Using the method, we need 3 broomsticks.
......

After checking the-possible method, we found that 2 are 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 an integer on each line and indicating the level number for each soldier. (less than digits);

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

Sample Input410203004523434

Sample Output12
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespacestd;intMain () {intdata[3005],ins[3005]; intN,ans;  while(cin>>N) {ans=0; memset (INS,0,sizeof(INS));  for(intI=0; i<n;i++) scanf ("%d",&Data[i]); Sort (Data,data+N);  for(intI=0; i<n;i++)        {            if(ins[i]==0) {Ins[i]=1; Ans++; intm=Data[i];  for(intj=i+1; j<n;j++)                {                    if(data[j]>m&&ins[j]==0) {Ins[j]=1; M=Data[j]; } }}} printf ("%d\n", ans); }    return 0;}

HDU 1800 Flying to the Mars

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.