1590: [Usaco2008 Dec]Secret Message 秘密信息
1590: [Usaco2008 Dec]Secret Message 秘密信息
Time Limit: 5 Sec Memory Limit: 32 MB
Submit: 209 Solved: 143
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
3 0 1 0
1 1
3 1 0 0
3 1 1 0
1 0
1 1
2 0 1
5 0 1 0 0 1
2 1 1
INPUT DETAILS:
Four messages; five codewords.
The intercepted messages start with 010, 1, 100, and 110.
The possible codewords start with 0, 1, 01, 01001, and 11.
Sample Output
3
1
1
2
HINT
0 matches only 010: 1 match 1 matches 1, 100, and 110: 3 matches 01 matches only 010: 1 match 01001 matches 010: 1 match 11 matches 1 and 110: 2 matches
Source
type
point=^node;
node=record
tt,ex:longint;
next:array[..] of point;
end;
var
i,j,k,l,m,n:longint;
head:point;
s1:ansistring;
function newp:point;
var p:point;
begin
new(p);p^.tt:=;p^.ex:=;
p^.next[]:=nil;p^.next[]:=nil;
exit(p);
end;
procedure insert(s1:ansistring);
var i:longint;p:point;
begin
p:=head;
for i:= to length(s1) do
begin
if p^.next[ord(s1[i])-]=nil then
p^.next[ord(s1[i])-]:=newp;
p:=p^.next[ord(s1[i])-];
inc(p^.tt);
end;
inc(p^.ex);
end;
function num(s1:ansistring):longint;
var i,j,k,l:longint;p:point;
begin
p:=head;j:=;k:=;l:=;
for i:= to length(s1) do
begin
if p^.next[ord(s1[i])-]=nil then break;
p:=p^.next[ord(s1[i])-];
k:=k+j;
j:=p^.ex;
l:=i;
end;
if l<>i then num:=k+j else num:=k+p^.tt;
end;
begin
readln(n,m);
head:=newp;
for i:= to n do
begin
read(l);s1:='';
for j:= to l do
begin
read(k);
s1:=s1+chr(+k);
end;
readln;
insert(s1);
end;
for i:= to m do
begin
read(l);s1:='';
for j:= to l do
begin
read(k);
s1:=s1+chr(+k);
end;
readln;
writeln(num(s1));
end;
readln;
end.
1590: [Usaco2008 Dec]Secret Message 秘密信息的更多相关文章
- bzoj 1590: [Usaco2008 Dec]Secret Message 秘密信息
1590: [Usaco2008 Dec]Secret Message 秘密信息 Description 贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息. 信息是二进制的,共 ...
- [Usaco2008 Dec]Secret Message 秘密信息
2794: [Usaco2008 Dec]Secret Message 秘密信息 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 7 Solved: 3 ...
- BZOJ1590:[Usaco2008 Dec]Secret Message秘密信息
浅谈\(Trie\):https://www.cnblogs.com/AKMer/p/10444829.html 题目传送门:https://lydsy.com/JudgeOnline/problem ...
- BZOJ1590 [Usaco2008 Dec]Secret Message 秘密信息
建立一颗trie树,记录下来每个点以它为结尾的字符串的个数cnt,和它的子树内有多少字符串size 于是查询的时候就只需要把沿途的cnt加起来,再加上最后的size就好了 /************* ...
- [BZOJ1590] [Usaco2008 Dec]Secret Message 秘密信息(字典树)
传送门 看到前缀就要想到字典树! 看到前缀就要想到字典树! 看到前缀就要想到字典树! #include <cstdio> #include <iostream> #define ...
- 【Trie】Secret Message 秘密信息
[题目链接]: https://loj.ac/problem/10054 [题意] 我认为这个题目最难的是题意: 其实分了两种情况: 1.如果当前文本串匹配不完,那么答案的是:匹配过程中遇到的模式串结 ...
- 洛谷P2922 [USACO008DEC] 秘密消息Secret Message [Trie树]
洛谷传送门,BZOJ传送门 秘密消息Secret Message Description 贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息. 信息是二进制的,共有M(1≤M≤5 ...
- [USACO08DEC] 秘密消息Secret Message
题目描述 Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret bin ...
- 「USACO08DEC」「LuoguP2922」秘密消息Secret Message(AC自动机
题目描述 Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret bin ...
随机推荐
- 状态开关按钮(ToggleButton)与开关(Switch)的功能与用法
状态开关按钮(ToggleButton)与开关(Switch)也是由Button派生出来的,因此它们的本质也是按钮,Button支持的各种属性.方法也适用于ToggleButton和Switch.从功 ...
- eclipse开发velocity实例(初学)
开发环境 Eclipse Java EE IDE for Web Developers.(Version: Helios Service Release 1) jdk1.6.0_07 ...
- CentOS 6.5下NFS安装配置
[root@local /]# yum -y install nfs-utils rpcbind3.创建共享目录:[root@local /]# mkdir /sharestore4.NFS共享文件路 ...
- POJ1077&&HDU1043(八数码,IDA*+曼哈顿距离)
Eight Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30127 Accepted: 13108 Special ...
- SDWebImage源码解读之SDWebImagePrefetcher
> 第十篇 ## 前言 我们先看看`SDWebImage`主文件的组成模块: SQL Server 系统提供功能的三个疑惑
本文目录列表: 1.SQL Server系统提供的部分疑惑概述2.系统函数调用时DEFAULT代替可选参数使用不统一3.队列字段列message_enqueue_time记录的是UTC日期时间 4.@ ...
- 嵌套的Try-Catch块--------异常处理(3)
当有一个Try块没有一个对应的异常可处理,则其父类的异常处理机制去处理.如果父类的异常处理机制不能处理,则java run-time system将会抛出一个异常. 例子: class Nest{ p ...
- POJ 2125 Destroying The Graph 二分图 最小点权覆盖
POJ2125 题意简述:给定一个有向图,要通过某些操作删除所有的边,每一次操作可以选择任意一个节点删除由其出发的所有边或者通向它的所有边,两个方向有不同的权值.问最小权值和的解决方案,要输出操作. ...
- git合并别的分支某次提交或合并
合并别的分支某次提交 master分支上改了一个bug.提交到master分支.现在在dev分支上开发,需要把master分支上改的那个bug合过来.步骤是:先在master分支上查改那个bug的SH ...