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 ...
随机推荐
- android studio 更新Gradle版本号方法
在导入其它项目时,常常因为gradle版本号不一致而导致不能编译 解决方法: 第一步: 按提示点击让它下载.事实上目的并非要它下载.因为这样速度会非常慢.这样做仅仅是为了让它在本地创建相应的文件夹结构 ...
- iOS对象(字典或数组)转化为JSon字符串
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setValue:@"he ...
- Mybatis资料
1. 入门案例 https://www.cnblogs.com/xdp-gacl/p/4261895.html 2. 详细笔记 以及配套视频教程: 笔记:https://blog.csdn.net/S ...
- 九度OJ 1014:排名 (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8267 解决:2469 题目描述: 今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑每题的分 ...
- 九度OJ 1013:开门人和关门人 (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5052 解决:2563 题目描述: 每天第一个到机房的人要把门打开,最后一个离开的人要把门关好.现有一堆杂乱的机房签到.签离记录,请 ...
- Python解释器是单线程应用 IO 密集型 计算密集型 GIL global interpreter lock
[Python解释器是单线程应用] [任意时刻,仅执行一个线程] 尽管Python解释器中可以运行多个线程,但是在任意给定的时刻只有一个线程会被解释器执行. [GIL锁 保证同时只有一个线程运行] 对 ...
- Pentaho BIServer Community Edtion 6.1 使用教程 第一篇 软件安装
一.简介: Pentaho BI Server 分为企业版和社区版两个版本.其中 社区版 CE(community edtion) 为免费版本. 二.下载CE版(CentOS): 后台下载命令: no ...
- Laravel5.5执行表迁移命令出现表为空的解决方案
今天在使用一个第三方包 laravel-admin 时,出现了这样的错误:SQLSTATE[42000]: Syntax error or access violation: 1103 Incorre ...
- 迁移博客到Github Pages
由于种种原因,我的博客迁移到了 https://phuker.github.io/ .虽然没有多少人气,但是希望能继续见证一个技术渣的成长.
- C# 操作SQLServer SMO中遇到的几个问题
业务需求:需要读取数据库中的所有库,得到库之后可以再做后续操作.(win 7 vs2010 sqlserver2008r2) 在读取数据库名的时候,就需要用到Microsoft.SqlServer. ...