Flying to the Mars

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11228    Accepted Submission(s): 3619

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
 
Author
PPF@JLU
 
由于数据疲弱,所以其实使用map就可以了,虽然这道题有人为的想卡掉STL做法,但是还存在漏洞。
代码:
 //#define LOCAL
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
using namespace std;
map<int,int>aa;
int main()
{
int n,i,maxc,b;
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
while(scanf("%d",&n)!=EOF){
aa.clear();
maxc=;
for(i=;i<=n;i++){
scanf("%d",&b);
aa[b]++;
if(maxc<aa[b])maxc=aa[b];
}
printf("%d\n",maxc);
}
return ;
}

不过,还是为了练一下手,就是用比较简单的trie树吧!

代码:218ms

 //#define LOCAL
#include<cstdio>
#include<cstring>
#include<cstdlib>
typedef struct node
{
struct node *child[];
int id;
}Trie;
int max(int a,int b)
{
return a>b?a:b;
}
int Insert(char *s,Trie *root)
{
Trie *cur=root,*curnew;
int i,pos;
for(i=;s[i]!='\0';i++)
{
pos=s[i]-'';
if(cur->child[pos]==NULL)
{
curnew = new Trie;
curnew->id=;
for(int j=;j<;j++)
curnew->child[j]=NULL;
cur->child[pos]=curnew;
}
cur=cur->child[pos];
}
cur->id++;
return cur->id;
}
void del(Trie *root)
{
Trie *cur=root;
for(int i=;i<;i++)
if(cur->child[i]!=NULL)
del(cur->child[i]);
delete cur;
}
char bb[];
int main()
{
int n,ans,i;
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
Trie *root;
while(scanf("%d",&n)!=EOF)
{
root=new Trie;
for(i=;i<;i++)
root->child[i]=NULL;
ans=;
while(n--){
scanf("%s",bb);
i=;
while(bb[i]==''&&bb[i+]!='\0')i++;
ans=max(ans,Insert(bb+i,root));
}
printf("%d\n",ans);
del(root);
}
return ;
}

注意几组数据:

4 004 04 0012 000

3 00 0 000

最新文章

  1. c# GridControl怎么换行
  2. Mac Security工具使用总结
  3. 安装Nexus
  4. dijit样式定制(三)Button、RadioButton、CheckBox
  5. Atitit dsl实现(1)------异常的库模式实现 &#160;异常的ast结构
  6. 《Javascript DOM编程艺术》 读书笔记 —— 好书,通俗易懂!!!!! 相当的严谨!!!!
  7. 升级CUDA版本导致VS2010错误:未找到导入的项目XXX,请确认&lt;Import&gt;声明中的路径正确,且磁盘上存在该文件
  8. 单片机TM4C123学习(八):SPI接口D/A
  9. (转)Java动态代理与CGLib代理
  10. JAVA中单例模式的几种实现方式
  11. css样式 浏览器的读取顺序
  12. CRM plugin 激活 停用 事件
  13. meta的Name为apple-itunes-app 是什么意思
  14. KEIL、uVision、RealView、MDK、KEIL C51区别比较
  15. cpp(第二章)
  16. 在IDEA中实战Git(转载自)
  17. C#神器 委托 + Unity神器 协程
  18. DEX、ODEX、OAT文件&amp;Dalvik和ART虚拟机
  19. 卸载QQ,360,迅雷,搜狗
  20. HP服务器 开启ILO

热门文章

  1. Trigger Execution Sequence Of Oracle Forms
  2. 大神写的一个纯CSS圆角框,膜拜!(支持IE9一下的低版本)
  3. POJ3009 Curling
  4. AS3 求两条直线的交点
  5. 理解odbc
  6. JS实现复选框全选全不选以及子复选框带动全选框的选中
  7. JavaWeb学习总结(三)—Servlet
  8. MATLAB中的nargin与varargin的用法
  9. Java中的Double类型计算
  10. 怎么进入BAT的研发部门?