HDU 1800:Flying to the Mars

Flying to the Mars

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 10817    Accepted Submission(s): 3469

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 could 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 could teach B; B could teach A; So , A B C are eligible to study on the same broomstick.

D could teach E;So D E are eligible to study on the same broomstick;

Using this method , we need 2 broomsticks.

Another method:

D could teach A; So A D are eligible to study on the same broomstick.

C could 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.

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 integer on each line , indicating the level number for each soldier.( less than 30 digits);

Output

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

Sample Input

4
10
20
30
04
5
2
3
4
3
4

Sample Output

1
2

题目说一把扫帚。高的可以教低的。做他的老师。低的当然是学生。问最少需要多少把扫帚。看同一个级别的最多有多少个。同一级别最多的就是需要扫帚的个数。典型的可以用hash做。。但是我不是。。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

const int maxn = 30000 + 50;

int n;
int a[maxn];
int ans;

int main()
{
    while(scanf("%d", &n) == 1 )
    {
        memset(a, 0, sizeof(a));
        int b;
        ans = -0x3f3f3f3f;
        int t = 1;
        int temp = 1;
        for(int i=1; i<=n; i++)scanf("%d", &a[i]);
        sort(a+1, a+n+1);
        if( n==1 )
            printf("1\n");
        else
        {
            for(int i=2; i<=n; i++)
            {
                if( a[i] == a[i-1] ){t++;temp = t;}
                else t = 1;
                if( temp>ans ){ans = temp;temp = 1;}
            }
            printf("%d\n", ans);
        }
    }

    return 0;
}

HDU 1800:Flying to the Mars

时间: 2024-10-08 07:47:04

HDU 1800:Flying to the Mars的相关文章

HDU 4059:The Boss on Mars(数学公式+容斥原理)

http://acm.hdu.edu.cn/showproblem.php?pid=4059 题意:给出一个n,求1~n里面与n互质的数的四次方的和是多少. 思路:不知道1~n的每个数的四次方的求和公式.看的是这篇:http://blog.csdn.net/acm_cxlove/article/details/7434864. 求和公式:(1^4+2^4+……+n^4)=(n*(n+1)*(2n+1)*(3*n*n+3*n-1))/30; 然后先求出1~n的每个数的四次方的求和,然后再减去n的因

HDU - 4059: The Boss on Mars (容斥 拉格朗日 优化)

pro: T次询问,每次给出N(N<1e8),求所有Σi^4 (i<=N,且gcd(i,N)==1) ; sol:  因为N比较小,我们可以求出素因子,然后容斥.  主要问题就是求1到P的4次幂和.  我们知道K次幂和是一个K+1次多项式. 这里有公式Pre=P*(P+1)*(2P+1)*(3P^2+3P-1)/30; 在不知道公式的情况下,我们可以用拉格朗日差值法求. 1,下面给出DFS容斥的代码 . #include<bits/stdc++.h> #define ll long

Flying to the Mars HDU - 1800(字典树)

Flying to the Mars HDU - 1800 题目链接:https://vjudge.net/problem/HDU-1800 题目:在8888年,地球由PPF帝国统治.随着人口的增长,PPF需要为新生儿寻找更多的土地.最后,PPF决定攻击统治火星的Kscinow.问题来了!士兵怎么能到达火星? PPF召集他的士兵并询问他们的建议. “匆匆......”一名士兵回答. “闭嘴 !我是否必须提醒你,从这里到火星没有任何道路!“PPF回复道. “飞!”另一个答案. PPF笑道:“聪明的

HDU 1800 Flying to the Mars (水题)

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11099    Accepted Submission(s): 3572 Problem Description In the year 8888, the Earth is ruled by the PPF Empire . As the popul

hdu 1800 Flying to the Mars(水 ,贪心)

其实就是求最大的相同的数的多少.. 我是把它当字符串输入..解决前导0的问题.. #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; int main() { char s[35]; int w[3500]; __int64 qq[3500]; int a; while(~scanf("%d",&a

hdu 1800 Flying to the Mars(简单模拟,string,字符串)

题目 又来了string的基本用法 //less than 30 digits //等级长度甚至是超过了int64,所以要用字符串来模拟,然后注意去掉前导零 //最多重复的个数就是答案 //关于string的修改增加的用法 #include <cstdio> #include<iostream> #include <cstring> #include <algorithm> #include<string> using namespace std

杭电 HDU ACM 1800 Flying to the Mars

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12471    Accepted Submission(s): 3963 Problem Description In the year 8888,  the Earth is ruled by the PPF Empire . As the pop

HDU 1800 Flying to the Mars(字典树)

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12767    Accepted Submission(s): 4048 Problem Description In the year 8888, the Earth is ruled by the PPF Empire . As the popu

杭电 1800 Flying to the Mars(贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10798    Accepted Submission(s): 3461 Problem Description In the year 8888, the