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 ...
随机推荐
- SkipList跳表(一)基本原理
一直听说跳表这个数据结构,说要学一下的,懒癌犯了,是该治治了 为什么选择跳表 目前经常使用的平衡数据结构有:B树.红黑树,AVL树,Splay Tree(这个树好像还没有听说过),Treep(也没有听 ...
- ssh无密码登陆屌丝指南
[0]写在前面 由于ssh 实现的是免密码登陆,大致步骤是: 0.1) client通过ssh登陆到server: 0.2) server检查家目录下的.ssh文件, 并发送公钥文件 authoriz ...
- 嵌入式驱动开发之---Linux ALSA音频驱动(一)
本文的部分内容参考来自DroidPhone的博客(http://blog.csdn.net/droidphone/article/details/6271122),关于ALSA写得很不错的文章,只是少 ...
- Xcode iphone模拟器运行不流畅
xcode该需要多高的配置......把这个取消就好了
- 转载 ----MAC 上搭建lua
MAC 上搭建lua 其实mac上搭建lua环境,google上大把资料,我只是整合一下,因为小弟搭建的时候确实碰到一些问题. 下载和安装lua:(转自这里) 1. 下载最新版的lua-5.2. ...
- 五个知识体系之-SQL语句大全
一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...
- native2ascii转码工具的使用
native2ascii转码工具是JDK自带的一种,方便我们将非unicode的编码文件转为unicode格式的文件,位置一般是位于JAVA_HOME/bin目录下. Why? 在做Java开发的时候 ...
- 我的Java开发学习之旅------>使用循环递归算法把数组里数据数组合全部列出
面试题如下:把一个数组里的数组合全部列出,比如1和2列出来为1,2,12,21. (面试题出自<Java程序员面试宝典>) 代码如下: import java.util.Arrays; i ...
- jforum二次开发教程
环境准备: 一.Tomcat服务器 首先需要在本地搭建tomcat.tomcat搭建过程本人博客中有,不再重复纪录.因为开始没有搭建成功,浪费了一定时间. 二.Mysql服务器 在 ...
- ABAP-创建货源清单
CALL FUNCTION 'ME_DIRECT_INPUT_SOURCE_LIST' *&-------------------------------------------------- ...