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 ...
随机推荐
- jmeter测试计划
测试计划配置 用户定义的变量: 测试计划上可以添加用户定义的变量.一般添加一些系统常用的配置.如果测试过程中想切换环境,切换配置,一般不建议在测试计划上添加变量,因为不方便启用和禁用,一般是直接添加用 ...
- 设计模式之单一职责原则(SRP)
自己之前写过一些关于设计模式的博客,但是大部分都写得比较匆忙.现在正好趁年前有时间,笔者打算好好地整理一下自己这块知识结构.开篇的第一个原则就是设计原则里面最简单的一个原则--单一职责原则. 想必大家 ...
- 关于在VI中查看BIN文件二进制值不对的问题
通常,我们在vim中,可以使用命令 %!xxd 来查看文件对应的二进制值.但是最近发生了一个事情,查看到的BIN文件二进制值和直接用hexdump打印出来的不一样. 经过检查定位,发现是因为vimrc ...
- HDU1864(背包)
最大报销额 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU5835
Danganronpa Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- win10环境下python3.5安装步骤
点我去Python官网下载 往下翻几页就能看到各种版本的Python,当前最新的是Python3.6,也没多大区别,我选择的是3.5.2 64位的,点击download 根据自己的电脑配置,我选择的是 ...
- ubuntu linux 中安装 mysql
三种安装方式: 1. 从网上安装 sudo apt-get install mysql-server.装完已经自动配置好环境变量,可以直接使用mysql的命令. 注:建议将/etc/apt/sourc ...
- 《JAVASCRIPT高级程序设计》错误处理与调试
一.错误处理 错误处理在程序设计中的重要性是毋庸置疑的,任何有影响力的web应用程序都需要一套完善的错误处理机制.良好的错误机制可以让用户得到提醒,知道发生了什么事. 1.try-catch语句 tr ...
- C# 数组、ArrayList、List、Dictionary的用法与区别
前言 在工作中经常遇到C#数组.ArrayList.List.Dictionary存取数据,但是该选择哪种类型进行存储数据,对于初学者的我一直不知道该怎么取舍.于是抽空好好看了下他们的用法和比较,在这 ...
- Kafka概念入门(一)
序:如何保证kafka全局消息有序? 比如,有100条有序数据,生产者发送到kafka集群,kafka的分片有4个,可能的情况就是一个分片保存0-25,一个保存25-50......这样消息在kafk ...