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 ...
随机推荐
- 分布式环境中三种Session管理方法的使用场景及优缺点
在分布式环境,管理Session通常使用下面三种方式: 一.Session Replication 方式管理 (即session复制) 简介:将一台机器上的Session数据广播复制到 ...
- 微信小程序怎么做出前端table的效果
wxml代码: <view class="container"> <view class="table"> &l ...
- 移动端H5页面遇到的问题总结
最近刚做完一个移动端的项目,产品之无敌,过程之艰辛,我就不多说了,记录下在这个项目中遇到的问题,以防万一,虽然这些可能都是已经被N多前辈解决掉了的问题,也放在这里,算是为自己漫漫前端路铺了一颗小石子儿 ...
- 实际开发中,实用的辅助iOS开发的工具
就目前所知,开发iOS绝大部分都是用Xcode,除此工具之外,还有几个好用的可以辅助实际开发中遇到的问题,拥有这种辅助开发技能,在工作中,甚至是以后的面试中,都可能会有不小的帮助. 下面推荐三个实用的 ...
- ADO.NET 防止SQL注入
规避SQL注入 如果不规避,在黑窗口里面输入内容时利用拼接语句可以对数据进行攻击 如:输入Code值 p001' union select * from Info where '1'='1 //这样可 ...
- Java虚拟机(JVM)默认字符集详解
Java中对字符串等进行转换字节数组时, 需要根据字符集编码来进行转换, 当不显示的指定字符集编码时(如: "测试".getBytes()), 会使用Charset.default ...
- asp.net core mvc权限控制:分配权限
前面的文章介绍了如何进行权限控制,即访问控制器或者方法的时候,要求当前用户必须具备特定的权限,但是如何在程序中进行权限的分配呢?下面就介绍下如何利用Microsoft.AspNetCore.Ident ...
- apche基于域名,ip,端口的配置
基于域名的服务端: 13 iptables -F 14 setenforce 0 15 ifconfig eth0 172.18.43.146 16 yum -y install bind bind- ...
- tableView的总结
// // ViewController.m // TableViewController // // Created by 王妍 on 16/3/23. // Copyright © 2016年 c ...
- css居中问题
学习过程中遇到css居中问题 , 也查阅了资料,每个人的方法都不尽相同,而且当时看懂了,过后就记混淆了;so作为一个前端小白,也来写一下俗话说好脑子不如烂笔头,毕竟自己知道的也不多,其实是抱着学习和交 ...