[Usaco2008 Dec]Secret Message 秘密信息
2794: [Usaco2008 Dec]Secret Message 秘密信息
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 7 Solved: 3
[Submit][Status][Web Board]
Description
信息是二进制的,共有M(1≤M≤50000)条.反间谍能力很强的约翰已经部分拦截了这些信息,知道了第i条二进制信息的前bi(l《bi≤10000)位.他同时知道,奶牛使用N(1≤N≤50000)条密码.但是,他仅仅了解第J条密码的前cj(1≤cj≤10000)位.
对于每条密码J,他想知道有多少截得的信息能够和它匹配.也就是说,有多少信息和这条密码有着相同的前缀.当然,这个前缀长度必须等于密码和那条信息长度的较小者.
在输入文件中,位的总数(即∑Bi+∑Ci)不会超过500000.
Input
Output
Sample Input
4 5
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
1
3
1
1
2
//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
HINT
Source
题解:
额,trie树乱搞题,用一个size记录有几个儿子,sum记录是尾节点的次数,遍历trie树,如果不是尾节点就加上sum,是尾节点就加上size。
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 500005
using namespace std;
int n,m,k,tot,ans;
int size[maxn],sum[maxn];
int son[maxn][];
int a[maxn];
char ch;
void read(int &x){
for (ch=getchar();!isdigit(ch);ch=getchar());
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
}
void insert(int k)
{
int p=;
for (int i=; i<=k; p=son[p][a[i]],i++)
{
if (!son[p][a[i]]) son[p][a[i]]=++tot;
size[p]++;
}
sum[p]++;
size[p]++;
}
void workout(int k)
{
int p=; ans=;
for (int i=; i<=k; p=son[p][a[i]],i++)
{
if (!son[p][a[i]]) break;
if (i!=k) ans+=sum[son[p][a[i]]]; else ans+=size[son[p][a[i]]];
}
printf("%d\n",ans);
}
int main()
{
// freopen("sec.in","r",stdin);
// freopen("sec.out","w",stdout);
int k;
read(n); read(m); tot=;
for (int i=; i<=n; i++)
{
read(k); for (int j=; j<=k; j++) read(a[j]);
insert(k);
}
for (int i=; i<=m; i++)
{
read(k);
for (int j=; j<=k; j++) read(a[j]);
workout(k);
}
return ;
}
[Usaco2008 Dec]Secret Message 秘密信息的更多相关文章
- 1590: [Usaco2008 Dec]Secret Message 秘密信息
1590: [Usaco2008 Dec]Secret Message 秘密信息 Time Limit: 5 Sec Memory Limit: 32 MBSubmit: 209 Solved: ...
- bzoj 1590: [Usaco2008 Dec]Secret Message 秘密信息
1590: [Usaco2008 Dec]Secret Message 秘密信息 Description 贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息. 信息是二进制的,共 ...
- 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 ...
随机推荐
- 为什么我的Android SDK Manager中只显示已安装的package?
如图.在菜单packages中,前两项我都是选了的 . 两种可能: 1. 明显是楼主连不上谷歌的更新服务器了,换成国内的吧,左上Tools-->Options弹出的界面有两个可以填写的 ,下面一 ...
- MySQL解决"is marked as crashed and should be repaired"故障
具体报错如下: Table '.\Tablename\posts' is marked as crashed and should be repaired 提示说论坛的帖子表posts被标记有问题,需 ...
- Jquery页面跳转
<mce:script type="text/javascript"><!-- $(function(){ var pn = $("#gotopagen ...
- 关于tomcat 成功运行之后内存泄露
在window-preferences 里 搜索 tomcat-jdk 加上以下内容即可 -Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize= ...
- Hadoop集群搭建的密钥配置SSH实现机制
- JSON对象和字符串转换
- zookeeper系列之异步通知模式-Watcher
1 watcher种类和事件种类 Watcher种类 1. zookeeper实例化时注入的默认Watcher 2. dataWatchers 一个Map<string Set<Watch ...
- elasticSearch indices VS type
elasticSearch 的中文文档 http://es.xiaoleilu.com/010_Intro/05_What_is_it.html https://www.elastic.co/blog ...
- away3d 汽车路线编辑器
2012年的时候,跟朋友去到一个公司,打算用away3d做一个赛车模拟养成游戏,后来由于种种原因,立项未成,由于朋友已经转行,自己也想对自己做过的事情有一些交代,所以将我负责的部分,赛道编辑器的源码公 ...
- cocos2dx 3.2 的中国象棋游戏
改编来源:http://cn.cocos2d-x.org/tutorial/lists?id=103 在cocos2dx官网看到了这么个教程,是cocos2dx 2.x版本的,于是用 cocos2dx ...