Scavenger Hunt
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2848   Accepted: 1553

Description

Background 
Bill has been the greatest boy scout in America and has become quite a superstar because he always organized the most wonderful scavenger hunts (you know, where the kids have to find a certain route following certain hints). Bill has retired now, but a nationwide election quickly found a successor for him, a guy called George. He does a poor job, though, and wants to learn from Bill's routes. Unfortunately Bill has left only a few notes for his successor. 
Problem 
Bill never wrote down his routes completely, he only left lots of little sheets on which he had written two consecutive steps of the routes. He then mixed these sheets and memorized his routes similarly to how some people learn for exams: practicing again and again, always reading the first step and trying to remember the following. This made much sense, since one step always required something from the previous step. 
George however would like to have a route written down as one long sequence of all the steps in the correct order. Please help him make the nation happy again by reconstructing the routes.

Input

The first line contains the number of scenarios. Each scenario describes one route and its first line tells you how many steps (3 <= S <= 333) the route has. The next S-1 lines each contain one consecutive pair of the steps on the route separated by a single space. The name of each step is always a single string of letters.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print S lines containing the steps of the route in correct order. Terminate the output for the scenario with a blank line.

Sample Input

2
4
SwimmingPool OldTree
BirdsNest Garage
Garage SwimmingPool
3
Toilet Hospital
VideoGame Toilet

Sample Output

Scenario #1:
BirdsNest
Garage
SwimmingPool
OldTree Scenario #2:
VideoGame
Toilet
Hospital

Source

TUD Programming Contest 2005, Darmstadt, Germany
这个题目的大概意思是找顺序,也可以说是找线索,先找第一个。

SwimmingPool OldTree(SwimmingPool在OldTree前面)
BirdsNest Garage 
Garage SwimmingPool
由此可知 BirdsNest -> Garage -> SwimmingPool -> OldTree.
然后再按这顺序每行一个名词输出.
这个题目运用的方法是用两个map保存前序和后序
然后找到第一个,再按顺序输出
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <string>
using namespace std;
int main()
{
int t;
cin >> t;
for(int i=; i<=t; i++)
{
map<string,string>next,pre;//定义两个保存前序,后序的map
int n;
cin >> n;
n=n-;
string tmp,s,s1;
while(n--)
{
cin >> s >> s1;
next[s] = s1;
pre[s1] = s;
}
while(pre[s]!="")
s= pre[s];//当前序为空的时候,说明找到第一个
printf("Scenario #%d:\n",i);
cout << s << endl;//先输出第一个
while(next[s]!="")//当后面不为空的时候输出下一个,最后一个不输出
{
cout << next[s] << endl;
s = next[s];//让s到下一个
}
cout << endl;
}
return ;
}

POJ 2491 Scavenger Hunt map的更多相关文章

  1. POJ 1066 Treasure Hunt(线段相交判断)

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4797   Accepted: 1998 Des ...

  2. poj 2418 Hardwood Species (map)

    题目:http://poj.org/problem?id=2418 在poj 上交题总是有各种错误,再次感叹各个编译器. c++ AC代码,G++为超时,上代码: #include<cstdio ...

  3. poj 2503 Babelfish (查找 map)

    题目:http://poj.org/problem?id=2503 不知道为什么 poj  的 数据好像不是100000,跟周赛的不一样 2000MS的代码: #include <iostrea ...

  4. POJ 1066 Treasure Hunt (线段相交)

    题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...

  5. POJ 1840 Eqs 二分+map/hash

    Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...

  6. 简单几何(线段相交) POJ 1066 Treasure Hunt

    题目传送门 题意:从四面任意点出发,有若干障碍门,问最少要轰掉几扇门才能到达终点 分析:枚举入口点,也就是线段的两个端点,然后选取与其他线段相交点数最少的 + 1就是答案.特判一下n == 0的时候 ...

  7. POJ 1066 Treasure Hunt(计算几何)

    题意:给出一个100*100的正方形区域,通过若干连接区域边界的线段将正方形区域分割为多个不规则多边形小区域,然后给出宝藏位置,要求从区域外部开辟到宝藏所在位置的一条路径,使得开辟路径所需要打通的墙壁 ...

  8. poj 1066 Treasure Hunt

    http://poj.org/problem?id=1066 #include <cstdio> #include <cstring> #include <cmath&g ...

  9. POJ 1066 Treasure Hunt(相交线段&amp;&amp;更改)

    Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...

随机推荐

  1. 华为matebook14vm虚拟机错误

    1.创建时显示不支持64位虚拟机 测试环境: 华为matebook14 window10 专业工作站版  1903   问题描述: 创建虚拟机时显示:此主机不支持64位解决方案   问题参考: 参考1 ...

  2. 接口测试时遇到 java 代码加密请求数据,用 python 的我该怎么办?

    前言 自动化测试应用越来越多了,尤其是接口自动化测试. 在接口测试数据传递方面,很多公司都会选择对请求数据进行加密处理. 而目前为主,大部分公司的产品都是java语言实现的.所以加密处理也是java实 ...

  3. SpringMVC学习笔记之---数据绑定

    SpringMVC数据绑定 一.基础配置 (1)pom.xml <dependencies> <dependency> <groupId>junit</gro ...

  4. 【作品】超实用C++分数类

    引言 我们说,编程语言的精髓在于封装,而面向对象语言完胜面向过程语言的原因就是具有更好的可封装性,而C++就是这样的一种多范型语言,常用而复杂的工作完全不必在每一份源文件中重敲,就好像我们不需要自己手 ...

  5. powerdesign进军(三)--mysql驱动配置

    目录 资源下载 powerdesign配置 总结 第二节我们已经安装了oracle的驱动,但是企业中还有一个重头数据库(mysql),今天来安装mysql驱动.mysql相较oracle比较简单. 资 ...

  6. vue.js中ref及$refs的使用及讲解

    关于ref和$refs的用法及讲解,vue.js中文社区( https://cn.vuejs.org/v2/api/#ref )是这么讲解的: ref 被用来给元素或子组件注册引用信息,引用信息将会注 ...

  7. H5中的history方法Api介绍

    最近公司在做一个微信公众号,看了项目源码,看到项目中用到了history的Api来进行控制浏览器的历史记录及前进/后退键: 下面来跟大家一起来捋捋history的Api方法和使用: history.p ...

  8. HlpViewer.exe 单独打开

    1.在桌面新建一个快捷键 2.添加HlpViewer.exe 的本地地址 3.在添加的地址后面添加 /catalogName VisualStudio12 4.保存快捷键即可 列: 桌面右键-> ...

  9. 《机器学习技法》---对偶SVM

    1.对偶问题的推导 为什么要求解对偶问题?一是对偶问题往往更容易求解,二是可以自然的引入核函数. 1.1 用拉格朗日函数将原问题转化为“无约束”等价问题 原问题是: 写出它的拉格朗日函数: 然后我们的 ...

  10. Appium+python自动化(三十二)- 代码写死一时爽,框架重构火葬场 - PageObject+unittest(超详解)

    简介 江湖有言:”代码写死一时爽,框架重构火葬场“,更有人戏言:”代码动态一时爽,一直动态一直爽