栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2945 Find the Clones

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2945 Find the Clones

#include <iostream>#include <cmath>#include <cstdio>#include <cstring>#include <cstdlib>#include <map>#include <set>#include <list>#include <queue>#include <stack>#include <string>#include <vector>#include <iomanip>#include <algorithm>using namespace std;typedef long long LL;#define clr(x, y) memset(x, y, sizeof(x))#define disc(x, y) memcpy(x, y, sizeof(y))#define Dc(x) fixed << setprecision(x)#define sf scanf#define pf printfconst double pi = 4.0 * atan(1.0);const double eps = 1e-8;const int INF = 1<<29;const int maxn = 20005;typedef struct Node {    int nxt[26], sum;}Node;Node tree[maxn * 16];int ans[maxn];int N, M, top;void init() {    clr(tree, 0), clr(ans, 0);top = 0;}void update(char str[]) {    int node = 0, len = strlen(str);for (int i = 0; i < len; i++) {    int tmp = str[i] - 'A';if (!tree[node].nxt[tmp]) {    tree[node].nxt[tmp] = ++top;node = top;}else {    node = tree[node].nxt[tmp];}}ans[tree[node].sum++]--;ans[tree[node].sum]++;}int main() {while (~sf("%d%d",&N,&M) && N+M) {    init();char name[25];for (int i = 1; i <= N; i++) {    sf("%s",&name);update(name);}for (int i = 1; i <= N; i++) {    pf("%dn",ans[i]);}}    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373467.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号