Trie 树的一些题

牛客练习赛11 假的字符串 (Trie树+拓扑找环)

链接:https://ac.nowcoder.com/acm/problem/15049

来源:牛客网

给定n个字符串,互不相等,你可以任意指定字符之间的大小关系(即重定义字典序),求有多少个串可能成为字典序最小的串,并输出它们

题解:对于第i个字符串来说,如果有一个串是他的前缀,那么这个前缀的字典序重定义后是肯定比他小的,所以我们用trie树保存前缀

​ 对于当前字符串,从该字符串的第i个字母向其父亲节点上的其他字母连边,表示存在大小关系\(str[i]>str[others]\) 这样就指定了 第i个字母的与其他字母的大小关系了,如果当前关系成立的话,就不会出现a>b>a这样的情况 即不会出现环的情况,所以我们用拓扑排序判断是否有环即可

/**
*        ┏┓    ┏┓
*        ┏┛┗━━━━━━━┛┗━━━┓
*        ┃       ┃  
*        ┃   ━    ┃
*        ┃ >   < ┃
*        ┃       ┃
*        ┃... ⌒ ...  ┃
*        ┃       ┃
*        ┗━┓   ┏━┛
*          ┃   ┃ Code is far away from bug with the animal protecting          
*          ┃   ┃ 神兽保佑,代码无bug
*          ┃   ┃           
*          ┃   ┃       
*          ┃   ┃
*          ┃   ┃           
*          ┃   ┗━━━┓
*          ┃       ┣┓
*          ┃       ┏┛
*          ┗┓┓┏━┳┓┏┛
*           ┃┫┫ ┃┫┫
*           ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 佛祖保佑 永无BUG
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const int maxn = 2e5 + 5 + 3e4;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double Pi = acos(-1);
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
LL lcm(LL a, LL b) {
return a / gcd(a, b) * b;
}
double dpow(double a, LL b) {
double ans = 1.0;
while(b) {
if(b % 2)ans = ans * a;
a = a * a;
b /= 2;
} return ans;
}
LL quick_pow(LL x, LL y) {
LL ans = 1;
while(y) {
if(y & 1) {
ans = ans * x % mod;
} x = x * x % mod;
y >>= 1;
} return ans;
} int du[27];
int mp[27][27];
int tuop() {
queue<int> qu;
while(!qu.empty()) qu.pop();
memset(du, 0, sizeof(du));
for(int i = 0; i < 26; ++i) {
for(int j = 0; j < 26; ++j) {
if(mp[i][j] == 1) du[j]++;
}
}
for(int i = 0; i < 26; ++i) {
if(du[i] == 0) qu.push(i);
}
int num = 0;
while(!qu.empty()) {
int u = qu.front();
qu.pop();
num++;
for(int i = 0; i < 26; ++i) {
if(mp[u][i] == 1) {
du[i]--;
if(du[i] == 0) qu.push(i);
}
}
}
return num;
}
const int maxChild = 26;
const int maxNode = maxn;
int tot = 0;
int child[maxNode | 10][maxChild];
//int cnt; //该结点后缀的数量
int isWord[maxNode];
void insert(string s) {
int pos, cur = 0;
for (int i = 0; i < s.length(); ++i) {
pos = s[i] - 'a';
if (child[cur][pos] == 0)
child[cur][pos] = ++tot;
cur = child[cur][pos];
//cnt++[cur];
}
isWord[cur] = 1;
}
int query(string s) {
int pos, cur = 0;
memset(mp, 0, sizeof(mp));
for (int i = 0; i < s.length(); ++i) {
pos = s[i] - 'a';
for(int j = 0; j < maxChild; ++j) {
if(pos == j) continue;
if(child[cur][j] != 0)
mp[pos][j] = 1;
}
if (child[cur][pos] == 0)
return 0;
if(isWord[cur])
return 0;
cur = child[cur][pos];
}
return tuop() == 26;
} string str[maxn];
int flag[maxn];
int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
IO;
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> str[i];
insert(str[i]);
}
int ans = 0;
for(int i = 1; i <= n; i++) {
if(query(str[i])) {
flag[i] = 1;
ans++;
}
}
// printf("%d\n", ans);
cout << ans << '\n';
for(int i = 1; i <= n; i++) {
if(flag[i]) {
cout << str[i] << '\n';
}
} return 0;
}

牛客wannafly 挑战赛14 B 前缀查询(trie树上dfs序+线段树)

链接:https://ac.nowcoder.com/acm/problem/15706

现在需要您来帮忙维护这个名册,支持下列 4 种操作:

  1. 插入新人名 si,声望为 a
  2. 给定名字前缀 pi 的所有人的声望值变化 di
  3. 查询名字为 sj 村民们的声望值的和(因为会有重名的)
  4. 查询名字前缀为 pj 的声望值的和

题解:一个非常明显的线段树操作,前缀可以看作是区间更新,区间查询,给定名字就是单点更新,单点查询,字典树上dfs序可以得到将树型结构变成一个线性的结构,然后用线段树维护即可,比较好的码力题了

/**
*        ┏┓    ┏┓
*        ┏┛┗━━━━━━━┛┗━━━┓
*        ┃       ┃  
*        ┃   ━    ┃
*        ┃ >   < ┃
*        ┃       ┃
*        ┃... ⌒ ...  ┃
*        ┃       ┃
*        ┗━┓   ┏━┛
*          ┃   ┃ Code is far away from bug with the animal protecting          
*          ┃   ┃ 神兽保佑,代码无bug
*          ┃   ┃           
*          ┃   ┃       
*          ┃   ┃
*          ┃   ┃           
*          ┃   ┗━━━┓
*          ┃       ┣┓
*          ┃       ┏┛
*          ┗┓┓┏━┳┓┏┛
*           ┃┫┫ ┃┫┫
*           ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 佛祖保佑 永无BUG
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double Pi = acos(-1);
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
LL lcm(LL a, LL b) {
return a / gcd(a, b) * b;
}
double dpow(double a, LL b) {
double ans = 1.0;
while(b) {
if(b % 2)ans = ans * a;
a = a * a;
b /= 2;
} return ans;
}
LL quick_pow(LL x, LL y) {
LL ans = 1;
while(y) {
if(y & 1) {
ans = ans * x % mod;
} x = x * x % mod;
y >>= 1;
} return ans;
}
struct Trie {
int nxt[maxn][26], tot;
int in[maxn], out[maxn], time_tag;
void init() {
memset(nxt, 0, sizeof(nxt));
tot = 1;
time_tag = 0;
}
void insert(string str) {
int p = 1;
int len = str.length();
for(int i = 0; i < len; i++) {
int ch = str[i] - 'a';
if(!nxt[p][ch]) {
nxt[p][ch] = ++tot;
}
p = nxt[p][ch];
}
}
int query(string str) {
int p = 1;
int len = str.length();
for(int i = 0; i < len; i++) {
int ch = str[i] - 'a';
if(!nxt[p][ch]) {
return 0;
}
p = nxt[p][ch];
}
return p;
}
void dfs(int u) {
in[u] = ++time_tag;
for(int i = 0; i < 26; i++) {
if(nxt[u][i]) {
dfs(nxt[u][i]);
}
}
out[u] = time_tag;
}
} trie;
LL sum[maxn << 2];
int lazy[maxn << 2];
int cnt[maxn << 2];
void push_up(int rt) {
sum[rt] = sum[ls] + sum[rs];
cnt[rt] = cnt[ls] + cnt[rs];
}
void build(int l, int r, int rt) {
sum[rt] = lazy[rt] = 0;
if(l == r) return;
int mid = (l + r) >> 1;
build(lson);
build(rson);
}
void push_down(int rt, int len) {
if(lazy[rt]) {
lazy[ls] += lazy[rt];
lazy[rs] += lazy[rt]; sum[ls] += lazy[rt] * cnt[ls];
sum[rs] += lazy[rt] * cnt[rs]; lazy[rt] = 0;
}
}
void update_pos(int pos, int val, int l, int r, int rt) {
if(l == r) {
sum[rt] += val;
cnt[rt]++;
return;
}
int mid = (l + r) >> 1;
push_down(rt, r - l + 1);
if(pos <= mid) update_pos(pos, val, lson);
else update_pos(pos, val, rson);
push_up(rt);
}
void update(int L, int R, int val, int l, int r, int rt) {
if(L <= l && r <= R) {
sum[rt] += cnt[rt] * val;
lazy[rt] += val;
return;
}
int mid = (l + r) >> 1;
push_down(rt, r - l + 1);
if(L <= mid) update(L, R, val, lson);
if(R > mid) update(L, R, val, rson);
push_up(rt);
}
LL query(int L, int R, int l, int r, int rt) {
if(L <= l && r <= R) {
return sum[rt];
}
int mid = (l + r) >> 1;
push_down(rt, r - l + 1);
LL ans = 0;
if(L <= mid) ans += query(L, R, lson);
if(R > mid) ans += query(L, R, rson);
return ans;
}
int op[maxn];
char buf[maxn];
string str[maxn];
int val[maxn];
int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d %s", &op[i], buf);
str[i] = buf;
if(op[i] <= 2) {
scanf("%d", &val[i]);
}
}
trie.init();
for(int i = 1; i <= n; i++) {
if(op[i] == 1) {
trie.insert(str[i]);
// cout << str[i] << endl;
}
}
trie.dfs(1);
// bug;
int tot = trie.tot;
// debug1(tot);
build(1, tot, 1);
for(int i = 1; i <= n; i++) {
if(op[i] == 1) {
int u = trie.query(str[i]);
int pos = trie.in[u];
// debug1(pos);
update_pos(pos, val[i], 1, tot, 1);
// bug;
} else if(op[i] == 2) {
int u = trie.query(str[i]);
if(u) {
int l = trie.in[u];
int r = trie.out[u];
update(l, r, val[i], 1, tot, 1);
}
} else if(op[i] == 3) {
int u = trie.query(str[i]);
if(u) {
int l = trie.in[u];
int r = trie.in[u];
LL ans = query(l, r, 1, tot, 1);
printf("%lld\n", ans);
} else {
printf("0\n");
}
} else if(op[i] == 4) {
int u = trie.query(str[i]);
if(u) {
int l = trie.in[u];
int r = trie.out[u];
LL ans = query(l, r, 1, tot, 1);
printf("%lld\n", ans);
} else {
printf("0\n");
} }
}
return 0;
}

牛客2018国庆集训 DAY1 D Love Live!(01字典树+启发式合并)

题意:给你一颗树,要求找出简单路径上最大权值为1~n每个边权对应的最大异或和

题解:

根据异或的性质我们可以得到 \(sum_{(u, v)}=sum_{(u, 1)} \bigoplus sum_{(v, 1)}\)那么我们可以预处理出所有简单路径上的异或值

对于路径上的最大权值来说,建图后,我们可以将边权进行排序,对于每一个权值为\(w_i(1-n)\)的连通块

现在我们已经得到了当前边权所在的连通块了,所以我们需要计算答案

也就是在这个边权所在的连通块内,计算出这个路径上所有边的异或和的最大值,我们可以用01字典树求出一个联通块内异或和的最大值

由于连通块的权值是从1开始的,所以对于权值为2的连通块来说,他是可以合并权值为1的块,我们用并查集将小的联通块往大的联通块上合并,这个就是启发式合并啦,基于一种贪心的思想

因为最多有n个联通块,合并的复杂度最多就是log(n)然后每次计算答案是log级别的,所以总的复杂度是nloglog级别的

/**
*        ┏┓    ┏┓
*        ┏┛┗━━━━━━━┛┗━━━┓
*        ┃       ┃  
*        ┃   ━    ┃
*        ┃ >   < ┃
*        ┃       ┃
*        ┃... ⌒ ...  ┃
*        ┃       ┃
*        ┗━┓   ┏━┛
*          ┃   ┃ Code is far away from bug with the animal protecting          
*          ┃   ┃ 神兽保佑,代码无bug
*          ┃   ┃           
*          ┃   ┃       
*          ┃   ┃
*          ┃   ┃           
*          ┃   ┗━━━┓
*          ┃       ┣┓
*          ┃       ┏┛
*          ┗┓┓┏━┳┓┏┛
*           ┃┫┫ ┃┫┫
*           ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 佛祖保佑 永无BUG
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double Pi = acos(-1);
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
LL lcm(LL a, LL b) {
return a / gcd(a, b) * b;
}
double dpow(double a, LL b) {
double ans = 1.0;
while(b) {
if(b % 2)ans = ans * a;
a = a * a;
b /= 2;
} return ans;
}
LL quick_pow(LL x, LL y) {
LL ans = 1;
while(y) {
if(y & 1) {
ans = ans * x % mod;
} x = x * x % mod;
y >>= 1;
} return ans;
}
struct EDGE {
int u, v, w, nxt;
EDGE() {};
EDGE(int _u, int _v, int _w) {
u = _u;
v = _v;
w = _w;
}
} edge[maxn << 1], G[maxn];
int head[maxn], tot;
bool cmp(EDGE a, EDGE b) {
return a.w < b.w;
}
void add_edge(int u, int v, int w) {
edge[tot].v = v;
edge[tot].w = w;
edge[tot].nxt = head[u];
head[u] = tot++;
}
int pre[maxn];
void dfs(int u, int fa) {
for(int i = head[u]; i != -1; i = edge[i].nxt) {
int v = edge[i].v;
if(v == fa) continue;
pre[v] = pre[u] ^ edge[i].w;
dfs(v, u);
}
}
struct Trie {
int id[maxn];
int ch[maxn * 400][2];
int cnt;
void init() {
memset(ch, 0, sizeof(ch));
cnt = 0;
}
void insert(int rt, int x) {
bitset<20> bit;
bit = x;
for(int i = 19; i >= 0; i--) {
if (!ch[rt][bit[i]])
ch[rt][bit[i]] = ++cnt;
rt = ch[rt][bit[i]];
}
}
int query(int rt, int x) {
bitset<20> bit;
bit = x;
int res = 0;
for(int i = 19; i >= 0; i--) {
bool flag = true;
int id = bit[i] ^ 1;
if(!ch[rt][id]) {
flag = false;
id ^= 1;
}
if(flag) res += 1 << i;
rt = ch[rt][id];
}
return res;
}
} trie;
int fa[maxn];
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if(x != y) {
fa[y] = x;
}
}
int n;
int sz[maxn];
vector<int> vec[maxn];
void init() {
memset(head, -1, sizeof(head));
tot = 0;
trie.init();
trie.cnt = n + 1;
pre[1] = 0;
for(int i = 1; i <= n; i++) {
fa[i] = i;
sz[i] = 1;
vec[i].clear();
trie.id[i] = i;
}
}
int main() {
#ifndef ONLINE_JUDGE
FIN
#endif scanf("%d", &n);
init();
for(int i = 1; i < n; i++) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
add_edge(u, v, w);
add_edge(v, u, w);
G[i] = EDGE(u, v, w);
}
dfs(1, 1);
// for(int i = 1; i <= n; i++) {
// printf("%d ", pre[i]);
// }
// printf("\n");
for (int i = 1; i <= n; ++i) {
trie.insert(trie.id[i], pre[i]);
vec[i].push_back(pre[i]);
}
// for(int i=1;i<=n;i++){
// printf("%d\n",fa[i]);
// }
sort(G + 1, G + n, cmp);
for (int i = 1; i < n; ++i) {
int x = G[i].u, y = G[i].v;
int fx = find(x), fy = find(y); if (sz[fx] > sz[fy]) {
swap(x, y);
swap(fx, fy);
}
int res = 0;
for (auto it : vec[fx]) {
res = max(res, trie.query(trie.id[fy], it));
}
for (auto it : vec[fx]) {
trie.insert(trie.id[fy], it);
vec[fy].push_back(it);
}
fa[fx] = fy;
sz[fy] += sz[fx];
printf("%d%c", res, i == n - 1 ? '\n' : ' ');
}
return 0;
}

Trie 树的一些题的更多相关文章

  1. ZOJ 1109 Language of FatMouse 【Trie树】

    <题目链接> 题目大意: 刚开始每行输入两个单词,第二个单词存入单词库,并且每行第二个单词映射着对应的第一个单词.然后每行输入一个单词,如果单词库中有相同的单词,则输出它对应的那个单词,否 ...

  2. HDU - 1251 统计难题(Trie树)

    有很多单词(只有小写字母组成,不会有重复的单词出现) 要统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). 每个单词长度不会超过10. Trie树的模板题.这个题内存把控不好容易MLE. ...

  3. Trie树-0/1字典树-DFS-1624. 最大距离

    2020-03-18 20:45:47 问题描述: 两个二进制串的距离是去掉最长公共前缀的长度之和.比如: 1011000和1011110的最长公共前缀是1011, 距离就是 len("00 ...

  4. 【模拟8.01】big(trie树)

    一道trie树的好题 首先我们发现后手对x的操作就是将x左移一位,溢出位在末尾补全 那么我们也可以理解为现将初值进行该操作,再将前i个元素异或和进行操作,与上等同. 那么我们等于转化了问题:     ...

  5. Hihicoder 题目1 : Trie树(字典树,经典题)

    题目1 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编 ...

  6. HDU 1251 Trie树模板题

    1.HDU 1251 统计难题  Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...

  7. Codeforces 633C Spy Syndrome 2 | Trie树裸题

    Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已 ...

  8. poj3630 Phone List (trie树模板题)

    Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26328   Accepted: 7938 Descr ...

  9. 刷题总结——分配笔名(51nod1526 trie树)

    题目: 班里有n个同学.老师为他们选了n个笔名.现在要把这些笔名分配给每一个同学,每一个同学分配到一个笔名,每一个笔名必须分配给某个同学.现在定义笔名和真名之间的相关度是他们之间的最长公共前缀.设笔名 ...

随机推荐

  1. poj 1655 Balancing Act 求树的重心【树形dp】

    poj 1655 Balancing Act 题意:求树的重心且编号数最小 一棵树的重心是指一个结点u,去掉它后剩下的子树结点数最少. (图片来源: PatrickZhou 感谢博主) 看上面的图就好 ...

  2. Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)

    参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...

  3. AtCoder Grand Contest 019 B - Reverse and Compare【思维】

    AtCoder Grand Contest 019 B - Reverse and Compare 题意:给定字符串,可以选定任意i.j且i<=j(当然i==j时没啥卵用),然后翻转i到j的字符 ...

  4. 12-3 DOM操作

    一 DOM基础 1 DOM介绍 DOM:文档对象模型.DOM 为文档提供了结构化表示,并定义了如何通过脚本来访问文档结构.目的其实就是为了能让js操作html元素而制定的一个规范. DOM就是由节点组 ...

  5. j2se--异常机制

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/quwenzhe/article/details/35610853   java异常机制中主要包含一个 ...

  6. 云原生生态周报 Vol. 7 | Docker 再爆 CVE

    业界要闻 Docker 基础镜像 Alpine 爆出提权漏洞(CVE-2019-5021):该CVE影响自 Alpine Linux 3.3 版本开始的所有 Docker 镜像.该漏洞的机制在于 Al ...

  7. mysql数据库之mysql下载与设置

    下载和安装mysql数据库 mysql为我们提供了开源的安装在各个操作系统上的安装包,包括ios,liunx,windows. mysql的安装,启动和基础配置-------linux版本 mysql ...

  8. day6_python之pickle、shelve序列化和反序列化

    pickle.shelve,python私有,支持所有python数据类型 一.pickle dic={'name':'egon','age':18} print(pickle.dumps(dic)) ...

  9. uva 11806 Cheerleaders (容斥)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  10. jq杂项方法/工具方法----each() grep() map()

    each() 用于循环数组 对象(单纯遍历) 返回 false 可提前停止循环.接受的参数是数组名和要执行的函数,函数参数为数组索引和当前元素. var arr = [30, 40, 50,1 ,8] ...