2012年浙大:Sharing
- 题目描述:
-
To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example, "loading" and "being" are stored as showed in Figure 1.
Figure 1
You are supposed to find the starting position of the common suffix (e.g. the position of "i" in Figure 1).
- 输入:
-
For each case, the first line contains two addresses of nodes and a positive N (<= 10^5), where the two addresses are the addresses of the first nodes of the two words, and N is the total number of nodes. The address of a node is a 5-digit positive integer, and NULL is represented by -1.
Then N lines follow, each describes a node in the format:
Address Data Next
where Address is the position of the node, Data is the letter contained by this node which is an English letter chosen from {a-z, A-Z}, and Next is the position of the next node.
- 输出:
-
For each case, simply output the 5-digit starting position of the common suffix. If the two words have no common suffix, output "-1" instead.
- 样例输入:
-
11111 22222 9
67890 i 00002
00010 a 12345
00003 g -1
12345 D 67890
00002 n 00003
22222 B 23456
11111 L 00001
23456 e 67890
00001 o 00010
00001 00002 4
00001 a 10001
10001 s -1
00002 a 10002
10002 t -1
- 样例输出:
-
67890
-1
题目来源:http://ac.jobdu.com/problem.php?pid=1468#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=;
struct Node{
int fr,ed;
char ch;
}no[MAXN];
struct Str{
char s[MAXN];
int pos[MAXN];
int len;
Str()
{
memset(s,,sizeof(s));
len=;
}
};
int HASH[MAXN];
void Handle(int next,Str &a)
{
while(next!=-)
{
int now=HASH[next];
a.s[a.len]=no[now].ch;
a.pos[a.len]=next;
next=no[now].ed;
a.len++;
}
}
int head,rear,n;
int main()
{ while(scanf("%d%d%d",&head,&rear,&n)!=EOF)
{
memset(HASH,,sizeof(HASH));
for(int i=;i<n;i++)
{
scanf("%d %c %d",&no[i].fr,&no[i].ch,&no[i].ed);
HASH[no[i].fr]=i;
}
Str a;
Str b;
Handle(head,a);
Handle(rear,b);
int res=-;
for(int i=a.len-,j=b.len-;i>=&&j>=;i--,j--)
{
if(a.s[i]!=b.s[j]) break;
res=a.pos[i];
}
if(res!=-)
printf("%05d\n",res);//输出5个数字,不足前导补0
else
printf("-1\n");
} return ;
}
2012年浙大:Sharing的更多相关文章
- 2012年浙大:Head of a Gang
题目描述: One way that the police finds the head of a gang is to check people's phone calls. If there is ...
- 2012年浙大:Hello World for U
题目描述: Given any string of N (>=5) characters, you are asked to form the characters into the shape ...
- 九度oj 1468 Sharing 2012年浙江大学计算机及软件工程研究生机试真题
题目1468:Sharing 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2687 解决:550 题目描述: To store English words, one method is ...
- [转]Installing SharePoint 2013 on Windows Server 2012 R2
转自:http://www.avivroth.com/2013/07/09/installing-sharepoint-2013-on-windows-server-2012-r2-preview/ ...
- The Truth About .NET Objects And Sharing Them Between AppDomains
From http://geekswithblogs.net/akraus1/archive/2012/07/25/150301.aspx I have written already some ti ...
- 云计算中心网络资源分配-Faircloud: sharing the network in cloud computing
网络资源同计算资源以及存储资源一样,是一种可被租户共享使用并提高利用率的资源.但是,不同租户的计算资源以及存储资源之间,有很强的隔离性,可以实现按需按比例分配的使用方式,但是网络资源却不可以. 主要原 ...
- 在Windows Server 2012 上安装Exchange 2013 服务器
前文:http://www.cnblogs.com/Liangw/archive/2011/09/19/2559944.html 安装准备: 1.加入一个存在的域(?如何建立一个域) 2.登录Wind ...
- Kaggle Bike Sharing Demand Prediction – How I got in top 5 percentile of participants?
Kaggle Bike Sharing Demand Prediction – How I got in top 5 percentile of participants? Introduction ...
- Sharing The Application Tier File System in Oracle E-Business Suite Release 12.2
The most current version of this document can be obtained in My Oracle Support Knowledge Document 13 ...
随机推荐
- xml 操作
/////////////////////////////////jaxp对xml文档进行解析/////////////////////////////////////////// 要操作的xml文件 ...
- POJ3009 Curling 2.0(DFS)
迷宫问题求最短路. 略有不同的是假设不碰到石头的话会沿着一个方向一直前进,出界就算输了.碰到石头,前方石头会消失,冰壶停在原地. 把这个当作状态的转移. DFS能够求出其最小操作数. #include ...
- c# .net Global.asax文件的作用
1 Global.asax文件的作用 先看看MSDN的解释,Global.asax 文件(也称为 ASP.NET 应用程序文件)是一个可选的文件,该文件包含响应 ASP.NET 或HTTP模块所引发的 ...
- HDFS源码分析心跳汇报之BPServiceActor工作线程运行流程
在<HDFS源码分析心跳汇报之数据结构初始化>一文中,我们了解到HDFS心跳相关的BlockPoolManager.BPOfferService.BPServiceActor三者之间的关系 ...
- 关于ejabberd限制单点登录
ejabberd 是对xmpp协议的完全实现,那么单纯的ejabberd是不提供该功能限制的,但是从我们的xmpp协议则可以完全的解决这个问题,我们通过jid对它进行限制,下面可以看一下jid的解释: ...
- delphi视频聊天
用Delphi开发视频聊天软件 一.引言 我们知道视频聊天软件的关键技术在于采集视频,并实时传输给聊天软件在线的人.对于视频的采集,这里采用微软公司的关于数字视频的一个软件包VFW(Video for ...
- 【BZOJ4519】[Cqoi2016]不同的最小割 最小割树
[BZOJ4519][Cqoi2016]不同的最小割 Description 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成两个部分,如果结点s,t不在同一个部分 ...
- python数据分析之Pandas:基本功能介绍
Pandas有两个主要的数据结构:Series和DataFrame. Series是一种类似于一维数组的对象,它由一组数据以及一组与之相关的数据标签构成.来看下它的使用过程 In [1]: from ...
- [egret+pomelo]实时游戏杂记(2)
[egret+pomelo]学习笔记(1) [egret+pomelo]学习笔记(2) [egret+pomelo]学习笔记(3) pomelo pomelo服务端介绍(game-server/con ...
- poj 3268 Silver Cow Party (最短路算法的变换使用 【有向图的最短路应用】 )
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13611 Accepted: 6138 ...