HDU 1800 Flying to the Mars -- 求一组数中出现频率最大的那个数出现的次数
来源:互联网 发布:在线视频转码 知乎 编辑:程序博客网 时间:2024/05/17 01:58
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1800
题意:有N个士兵,每个士兵有一个属于自己的等级,他们要学一项魔杖飞行技术,等级高的士兵可以教等级低的士兵,等级低的士兵不可以教等级高的士兵,一个士兵只能教一个士兵,一个士兵也只能被一个士兵教,能形成这样的教学关系的士兵组成一个教学组,需要一根魔杖,问最少需要多少根魔杖。即求
求一组数中出现频率最大的那个数出现的次数!
可以用hash,也可以用字典树
/*http://acm.hdu.edu.cn/showproblem.php?pid=1800Flying to the Marsnext[] 也就是数字 0-9 */#include<cstdio>#include<cstring>#include<stdlib.h>typedef struct node{ int count; struct node* next[11]; node(int _count = 0) { count = _count; int i; for (i = 0; i < 11; i++) { next[i] = NULL; } }}trie;int max;void insert(trie *T, char* s) { int i = 0; trie* p = T; trie* q; while (s[i] != '\0') { int id = s[i] - '0'; if (p->next[id] == NULL) { q = new node(0); p->next[id] = q; } p = p->next[id]; // p 跳到下一个 i++; } p->count++; // p 为 最后的定位 数量加加 if (p->count > max) max = p->count;}int main(){ //freopen("in", "r", stdin); int n, i; char s[35]; trie* T; while (scanf("%d", &n) != EOF) { T = new node(0); max = 0; while (n--) { scanf("%s", s); i = 0; while (s[i++] == '0'); // 清除前面的0 insert(T , &s[i-1]); // & 取地址 } printf("%d\n", max); } return 0;}
0 0
- HDU 1800 Flying to the Mars -- 求一组数中出现频率最大的那个数出现的次数
- 打印一组数字中最大数及出现的次数
- 求向量中出现频率最大的数
- 求出现次数大于数组长度一半的那个数
- JAVA求 出现次数最多数值最大的数
- 找出一组数出现次数超过一半的数
- c++求数组中出现频率最高的数
- HDU1029:Ignatius and the Princess IV -DP求一列数中出现次数最多的数的次数
- hdu 1800 Flying to the Mars map的基本用法
- c++求一组数据中出现次数最多的数《c++程序设计原理与实践》第4章习题16
- 求出现次数超过一半的数
- 求出现次数最多的数
- 求出现次数最多的数
- 求出现频率最多的那个字母和出现的次数
- 求一个数组中出现次数最多的数
- 求一个数组中出现次数最多的数
- 求数组中出现次数超过一半的数
- 求整数序列中出现次数最多的数
- IE兼容性问题之trim
- iOS NSNumber
- 正则表达式三
- 史上最全的央企控股上市公司一览------央企改革股票
- python代码`if not x:` 和`if x is not None:`和`if not x is None:`使用
- HDU 1800 Flying to the Mars -- 求一组数中出现频率最大的那个数出现的次数
- 关于it-ebooks.info无法下载的一种解决方法
- DJY-broswer 利用html做桌面应用
- 我的openwrt学习笔记(二十三):MTK7688 elian一键配置原理
- nyoj 44 子串和【最大子串和】
- android Java与JNI层互相调用
- Node.js + MongoDB学习
- LeetCode 题解(195) : Contains Duplicate
- 类Hash结构词典