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 ...
随机推荐
- pandaboard es 制作SD启动卡OMAP4460
1. 本次使用的是chipsee的板子,带屏幕的,先把资料传到Ubuntu的共享目录下 2. 进入共享目录 /mnt/hgfs/ubuntu_share/pandboard_es_linux# 3. ...
- dp合集 广场铺砖问题&&硬木地板
dp合集 广场铺砖问题&&硬木地板 很经典了吧... 前排:思想来自yali朱全民dalao的ppt百度文库免费下载 后排:STO朱全民OTZ 广场铺砖问题 有一个 W 行 H 列的广 ...
- idea 安装后需要手动设置 64位的vmoptions (为了更好的性能和体验)
- toString()方法简单分析
问题描述 今天在使用spotbugs代码走查时发现这样一个问题,如下, String[] myArray=new String[] {"1","2"," ...
- C# webapi 路由规则和接收数据
1:新建的web api项目 默认的访问api方式: (get,post,delect,put) api+控制器 以Post为例子 post提交单个参数: 接收方法 post提交多个参数 接 ...
- Flask 路由相关操作
URL Route URL 后接 / 作为目录级访问 URL 后不接 / 作为文件级访问 from flask import Flask app = Flask(__name__) @app.rout ...
- 百度云 win10 125%界面模糊 解决
右击图标 ->兼容性->更改高DPI设置 -> 替代高DPI缩放行为.打√
- 8个数据清洗Python代码,复制可用,最长11行 | 资源
最近,大数据工程师Kin Lim Lee在Medium上发表了一篇文章,介绍了8个用于数据清洗的Python代码. 数据清洗,是进行数据分析和使用数据训练模型的必经之路,也是最耗费数据科学家/程序员精 ...
- url乱码问题
//url乱码,有时候要解码2次才能成功 String url=URLDecoder.decode(URLDecoder.decode(returnUrl, "UTF-8"),&q ...
- SQL Server变量杂谈
学习SQL的过程有进步的话还是一件很美妙的事情的 在第一家公司虽然只呆了两年,但是感觉是我进步最快的两年.那时候工作和生活都挺充实的,每天都有一点点的收获和付出,其中最大的收获莫过于掌握一些核心技能. ...