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. asp.net ashx处理程序中switch case的替代方案总结

    目录 1.用委托字典代替switch...case; 2.利用反射替代switch...case: 3.比较两种方案 4.其他方案 4.说明 5.参考 在开发 asp.net 项目中,通常使用一般处理 ...

  2. 自定义SWT控件三之搜索功能下拉框

    3.搜索功能下拉弹出框 package com.view.control.select; import java.util.ArrayList; import java.util.LinkedList ...

  3. lvs+keepalived 高可用及负载均衡

    一.环境准备 VIP:10.18.43.30 dr1:10.18.43.10 dr2:10.18.43.20 web1:10.18.43.13 web2:10.18.43.14 结构图 (一).预处理 ...

  4. (14)ASP.NET Core 中的日志记录

    1.前言 ASP.NET Core支持适用于各种内置和第三方日志记录提供应用程序的日志记录API.本文介绍了如何将日志记录API与内置提供应用程序一起使用. 2.添加日志提供程序 日志记录提供应用程序 ...

  5. luogu1373_小a和uim之大逃离 多维dp

    传送门 巧妙之处在于dp的设计只用设计差值即可,因此不会mle,枚举的顺序问题也解决了 #include <bits/stdc++.h> using namespace std; #def ...

  6. 伽马变换(一些基本的灰度变换函数)基本原理及Python实现

    1. 基本原理 变换形式 $$s=cr^{\gamma}$$ c与$\gamma$均为常数 可通过调整$\gamma$来调整该变换,最常用于伽马校正与对比度增强 2. 测试结果 图源自skimage ...

  7. element ui 退出功能

    <template> <el-container class="home-wrapper"> <el-header> <el-row ty ...

  8. 码农"混子"的思想转变

    首先介绍一下自己,在高中的时候学校对于我们这种普通班级采取的都是放养状态,所以高中的学习真是不咋地,可能除了自己擅长的数学以外其他也就考个三四十分,后来磕磕绊绊的在打游戏之余也会学习,第一次参加高考跟 ...

  9. 机器学习tips

    1 为什么随机梯度下降法能work? https://www.zhihu.com/question/27012077中回答者李文哲的解释   2 随机梯度下降法的好处? (1)加快训练速度(2)噪音可 ...

  10. K8S搭建-1 Master 2 Workers(dashboard+ingress)

    本文讲述k8s最新版的搭建(v1.15.2) 分如下几个topic步骤: 各个节点的基本配置 master节点的构建 worker节点的构建 安装dashboard 安装ingress 常见命令 do ...