待修改 URAL 1542
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+2e4+11;
const int dep = 666;
const int len = 30;
struct AAA{
string str;
int cnt;
}a[maxn];
bool cmp(AAA a,AAA b){
if(a.cnt!=b.cnt) return a.cnt>b.cnt;
// return a.str<b.str;
return lexicographical_compare(a.str.begin(),a.str.end(),b.str.begin(),b.str.end());
}
struct TRIE{
int son[dep][len];
bool edp[maxn];//is endPoint?
vector<int> vec[maxn];//idx of str
int tot,root;
int node(){
for(int i = 0; i < len; i++) son[tot][i]=-1;
edp[tot]=0;
return tot++;
}
void init(){
memset(son,-1,sizeof son);
memset(vec,0,sizeof vec);
tot=0;
root=node();
}
void insert(char str[]){
int now=root;
int llen = strlen(str);
for(int i = 0; i < llen; i++){
int idx=str[i]-'a';
if(son[now][idx]==-1) son[now][idx]=node();
now=son[now][idx];
}
edp[now]=1;
}
// bool asprefix(char str[]){
// int llen=strlen(str);
// int now=root;
// bool reach=0;
// for(int i = 0; i < llen; i++){
// int idx=str[i]-'a';
// if(son[now][idx]==-1&&reach) return 1;
// if(son[now][idx]==-1&&!reach) return 0;
// now=son[now][idx];
// if(edp[now]) reach=1;
// }
// return reach;
// }
void insert(string str,int k){
int now=root;
int llen=str.length();
for(int i = 0; i < llen; i++){
int idx = str[i]-'a';
if(son[now][idx]==-1) break;
now=son[now][idx];
if(edp[now]&&vec[now].size()<10) vec[now].push_back(k);
}
}
int getid(char str[]){
int now=root;
int llen=strlen(str);
for(int i = 0; i < llen; i++){
int idx=str[i]-'a';
now=son[now][idx];
}
return now;
}
}trie;
char s[maxn][30];
int main(){
ios::sync_with_stdio(false);
int n,m;
while(cin>>n){
for(int i = 1; i <= n; i++){cin>>a[i].str>>a[i].cnt;}
cin>>m;
trie.init();
for(int i = 1; i <= m; i++){
cin>>s[i];
trie.insert(s[i]);
}
sort(a+1,a+n,cmp);
for(int i = 1; i <= n; i++){
trie.insert(a[i].str,i);
}
for(int i = 1; i <= m; i++){
int id=trie.getid(s[i]);
if(i>1) cout<<endl;
for(int j = 0; j < trie.vec[id].size(); j++){
cout<<a[trie.vec[id][j]].str<<endl;
}
}
}
return 0;
}
待修改 URAL 1542的更多相关文章
- URAL 1542. Autocompletion 字典树
给你最多10w个单词和相应的频率 接下来最多1w5千次询问 每次输入一个字符串让你从前面的单词中依照频率从大到小输出最多10个以该字符串为前缀的单词 開始把单词建成了字典树 然后每次询问找到全部满足条 ...
- URAL 1934 Black Spot --- 最短的简单修改
右侧是1.维护的同时保持最短路p值至少,我有直接存款(1-p).该概率不满足,为了使这个值极大. #include <iostream> #include <cstdlib> ...
- ural 2062 Ambitious Experiment
2062. Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scient ...
- ural 1251. Cemetery Manager
1251. Cemetery Manager Time limit: 1.0 secondMemory limit: 64 MB There is a tradition at the USU cha ...
- HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- ●线段树的三个题(poj 3225,hdu 1542,hdu 1828)
●poj 3225 Help with Intervals(线段树区间问题) ○赘述题目 给出以下集合操作: 然后有初始的一个空集S,和以下题目给出的操作指令,并输入指令: 要求进行指令操作后,按格式 ...
- 【BZOJ1814】Ural 1519 Formula 1 (插头dp)
[BZOJ1814]Ural 1519 Formula 1 (插头dp) 题面 BZOJ Vjudge 题解 戳这里 上面那个链接里面写的非常好啦. 然后说几个点吧. 首先是关于为什么只需要考虑三进制 ...
- HDU 1542 - Atlantis - [线段树+扫描线]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 1754 I Hate It<区间最值 单点修改>
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- sql语句中的问号是干什么的???
1.实例代码一: String sql = "SELECT userid,name FROM tuser WHERE userid=? AND password=?" ; pst ...
- if __name__ == "__main__": 的使用
#!/usr/bin/env python from qq.lib.a2 import register from qq.lib.a3 import login def main(): while T ...
- valgrind详解
调不尽的内存泄漏,用不完的Valgrind Valgrind 安装 1.valgrind 安装包下载地址:http://valgrind.org/downloads/repository.html(使 ...
- OpenNi安装示例
1.下载OpenNi https://structure.io/openni 解压,点击运行 选择安装目录,默认即可 安装过程中有弹框,选择 安装 点击 完成 在相应的安装目录下即可找到
- CodeForces 384E Propagating tree (线段树+dfs)
题意:题意很简单么,给定n个点,m个询问的无向树(1为根),每个点的权值,有两种操作, 第一种:1 x v,表示把 x 结点加上v,然后把 x 的的子结点加上 -v,再把 x 的子结点的子结点加上 - ...
- Spring学习大纲
1.BeanFactory 和 FactoryBean? 2.Spring IOC 的理解,其初始化过程? 3.BeanFactory 和 ApplicationContext? 4.Spring B ...
- sqlserver 时间差转换为天时分秒
DECLARE @starttime DATETIME = '2016-12-01' , @endtime DATETIME = '2016-12-02 14:56:39.927'; DECLARE ...
- ASP.NET MVC Razor语法及实例
1.混合HTML与Razor脚本 知识点:(1).cshtml怎样引用访问数据, (2).if for 与html嵌套 @using System.Data @using CIIC.TCP.Enti ...
- javascript 取掉空格自定义函数
js 取掉空格自定义函数 //取掉左右空格: function trim(str){ return str.replace(/(^\s*)|(\s*$)/g, ""); } // ...
- dubbo心跳机制 (3)
此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 二.consumer端心跳机制 //创建ExchangeClie ...