hdu1800 Flying to the Mars--字典树
来源:互联网 发布:淘宝整点秒杀 编辑:程序博客网 时间:2024/06/05 03:31
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800
题意:n个人,每个人一个数字,数字长度最长是30位,也就是必须得用字符串存,现在每人要学习骑扫帚去打仗,数字大的可以做数字小的师傅,这样他们可以用一个扫帚。问最后最少需要多少扫帚?
分析:坑点:一个人的数字可能是01,001,那这样的数据其实都是1,所以需要处理下。
#define _CRT_SECURE_NO_DEPRECATE #include<iostream>#include<vector>#include<cstring>#include<queue>#include<stack>#include<algorithm>#include<cmath>#define INF 99999999#define eps 0.0001using namespace std;int n;int ans;char s[50];struct Node{Node * next[10];int c;Node(){c = 0;for (int i = 0; i <= 9; i++)next[i] = nullptr;}}*pRoot;void add(char * p){int len = strlen(p);Node * pt = pRoot;for (int i = 0; i < len; i++){if (!pt->next[p[i] - '0'])pt->next[p[i] - '0'] = new Node;pt = pt->next[p[i] - '0'];}pt->c++;if (pt->c > ans)ans = pt->c;}void del(Node * p){for (int i = 0; i < 10; i++)if (p->next[i])del(p->next[i]);delete p;}int main(){while (~scanf("%d", &n)){pRoot = new Node;ans = 0;for (int i = 0; i < n; i++){scanf("%s", s);char * p = s;while (*p == '0')//去0p++;add(p);}printf("%d\n", ans);del(pRoot);}return 0;}
1 0
- 【字典树】 hdu1800 Flying to the Mars
- hdu1800 Flying to the Mars (字典树)
- Hdu1800 - Flying to the Mars - 字典树
- HDU1800 Flying to the Mars【字典树】
- hdu1800 Flying to the Mars--字典树
- Flying to the Mars hdu1800 字典树
- hdu1800 Flying to the Mars(字典树)
- HDU1800 Flying to the Mars Tire树
- HDU1800 Flying to the Mars
- HDU1800 Flying to the Mars
- HDU1800-Flying to the Mars
- hdu1800 Flying to the Mars
- hdu1800 Flying to the Mars(map)
- hdu1800 Flying to the Mars ELFHash/BKDHash
- HDU1800 Flying to the Mars 【贪心】
- Flying to the Mars hdu1800 trie
- HDU1800 Flying to the Mars(贪心)
- Flying to the Mars(字典树)
- 微信公众号刷量被曝光,自媒体泡沫有多大?
- MYSQL学习笔记----子查询
- 分页查询综合案例
- [从头学绘画] 第03节 线条人
- Android拍照,相册选择图片以及Android6.0权限管理
- hdu1800 Flying to the Mars--字典树
- HDU ACM 11 2010 水仙花数
- 包装类与自动装箱
- Android通过JDBC连接MySql数据库时遇到的问题(1)
- UVA 227 - Puzzle
- php重构优化一例——模板方法模式应用
- ROS导航-----slam_gmapping简介
- JAVA 线程
- 欢迎使用CSDN-markdown编辑器