Flying to the Mars
Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 8352 Accepted Submission (s): 2713
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.
Input input 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);
Output for each case, output the minimum number of broomsticks on a.
Sample Input
4 10 20 30 04 5 2 3 4 3 4
Sample Output
1 2
Author Ppf@jlu
Recommend LCY
Import Java.math.BigInteger;
Import Java.util.HashMap;
Import Java.util.Map;
Import Java.util.Scanner;
public class Main {
/**
* @param args */public
static void Main (string[] args) {
//TODO Auto-generat Ed method stub
Scanner input=new Scanner (system.in);
while (Input.hasnext ()) {
map<biginteger,integer> map=new hashmap<biginteger,integer> ();
int N=input.nextint ();
int max=integer.min_value;
while (n-->0) {
BigInteger a=input.nextbiginteger ();
Integer Value=map.get (a);
if (value==null) {
value=0;
}
if (++value>max)
max=value;
Map.put (A, value);
}
SYSTEM.OUT.PRINTLN (max);}}}