Shortest Prefixes POJ - 2001(统计次数)
题意:
输出每个单词的缩写 使得每个单词 互不相同。。
解析:
统计每个前出现的次数。。。然后在查询的时候 遇到次数为1的返回即可。。
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int trie[maxn][], sum[maxn];
int rt, tot;
char str[maxn][];
vector<char> v;
void build(char *s)
{
int len = strlen(s);
rt = ;
for(int i=; i<len; i++)
{
int x = s[i] - 'a';
if(trie[rt][x] == ) trie[rt][x] = ++tot;
rt = trie[rt][x];
sum[rt]++;
}
} void qp(char *s)
{
int len = strlen(s);
rt = ;
for(int i=; i<len; i++)
{
v.push_back(s[i]);
int x = s[i] - 'a';
if(trie[rt][x] == ) return;
rt = trie[rt][x];
if(sum[rt] == ) return;
}
} int main()
{
int cnt = ;
while(cin>> str[++cnt])
{
build(str[cnt]);
}
rap(i, , cnt)
{
v.clear();
qp(str[i]);
cout<< str[i] << " ";
for(int i=; i<v.size(); i++)
cout<<v[i];
cout<<endl;
} return ;
}
Shortest Prefixes POJ - 2001(统计次数)的更多相关文章
- OpenJudge/Poj 2001 Shortest Prefixes
1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...
- POJ 2001 Shortest Prefixes (Trie)
题目链接:POJ 2001 Description A prefix of a string is a substring starting at the beginning of the given ...
- POJ 2001 Shortest Prefixes(字典树活用)
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21651 Accepted: 927 ...
- poj 2001:Shortest Prefixes(字典树,经典题,求最短唯一前缀)
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12731 Accepted: 544 ...
- POJ 2001:Shortest Prefixes
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16782 Accepted: 728 ...
- poj 2001 Shortest Prefixes trie入门
Shortest Prefixes 题意:输入不超过1000个字符串,每个字符串为小写字母,长度不超过20:之后输出每个字符串可以简写的最短前缀串: Sample Input carbohydrate ...
- POJ 2001 Shortest Prefixes(字典树)
题目地址:POJ 2001 考察的字典树,利用的是建树时将每个点仅仅要走过就累加.最后从根节点開始遍历,当遍历到仅仅有1次走过的时候,就说明这个地方是最短的独立前缀.然后记录下长度,输出就可以. 代码 ...
- POJ 2001 Shortest Prefixes 【 trie树(别名字典树)】
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15574 Accepted: 671 ...
- poj 2001 Shortest Prefixes(字典树trie 动态分配内存)
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15610 Accepted: 673 ...
随机推荐
- HDU 6086 Rikka with String
Rikka with String http://acm.hdu.edu.cn/showproblem.php?pid=6086 题意: 求一个长度为2L的,包含所给定的n的串,并且满足非对称. 分析 ...
- git在windows7下面使用
1. 首选安装. 2. 打开Git Bash 3. 输入,就是配置一下用户名啥的 $ git config --global user.name "Jack Liao" $ git ...
- RDS for MySQL有哪些限制
原文来自:https://help.aliyun.com/knowledge_detail/41834.html 1.不支持在命令行创建数据库和数据库账号.只支持在RDS管理控制台操作. 2.不支持M ...
- linux 命令缩写
su super user apt advanced packaging tool ifconfig interface configuration so shared object fsp frac ...
- selenium webdriver API详解(一)
本系列主要讲解webdriver常用的API使用方法(注意:使用前请确认环境是否安装成功,浏览器驱动是否与谷歌浏览器版本对应) 一:打开某个网址:get() from selenium import ...
- Java普通编程和Web网络编程准备工作
一.工具下载 链接:https://pan.baidu.com/s/1geOdq3h 密码:pzl5 二.Java普通编程 解压下载的资料,并按readme.txt安装jdk和Eclipse. 三.J ...
- 在Unity中使用带碰撞体的TiledMap
虽然最近Unity2018版本推出了自己的瓦片地图,但是这个瓦片地图有点BUG,在场景内把瓦片地图铺好做成预制体,动态生成的时候居然丢失了碰撞体,于是我决定还是使用Tiled软件绘制地图并使用Tile ...
- centos7.2部署docker-17.06.0-ce的bug:Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"\"".
现象: 操作系统:centos 7.2 kernel 3.10.0-327.el7.x86_64 mesos:1.3.0 docker:docker-17.06.0-ce 在做mesos验证时,通过m ...
- 软件工程第八周PSP
1.本周PSP 2.本周进度条 代码行数 0 博文字数 356 知识点 无 3.时间分配饼状图 4.折线图
- 软件工程-东北师大站-第五次作业(PSP)
1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 4.本周PSP饼状图