暑假集训第三周STL L - Scavenger Hunt
来源:互联网 发布:伊沃人工智能 编辑:程序博客网 时间:2024/06/04 18:51
L - Scavenger Hunt
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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.
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
24SwimmingPool OldTreeBirdsNest GarageGarage SwimmingPool3Toilet HospitalVideoGame Toilet
Sample Output
Scenario #1:BirdsNestGarageSwimmingPoolOldTreeScenario #2:VideoGameToiletHospital
运用map 散列表,对应关系,依次找出符合条件的答案
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
#include<stdio.h>#include<algorithm>#include<map>#include<string>#include<iostream>using namespace std;int main(){ int n,num=1; scanf("%d",&n); while(n--) { map<string,string>m1; map<string,int>m2; int m; scanf("%d",&m); for(int i=0; i<m-1; i++) { getchar(); char a[100],b[100]; scanf("%s %s",a,b); string s1,s2; s1=a,s2=b; m1[s1]=s2; m2[s2]=1; } map<string,string>::iterator it; string ans; for(it=m1.begin(); it!=m1.end(); it++) { if(m2[(*it).first]==0) ans=(*it).first; } if(num!=1) printf("\n"); printf("Scenario #%d:\n",num++); cout<<ans<<endl; int sum=m-1; while(sum) { ans=m1[ans]; cout<<ans<<endl; sum--; } } return 0;}
0 0
- 暑假集训第三周STL L - Scavenger Hunt
- 暑假集训第三周 STL D - 排列
- 暑假集训第三周 STL 双队列
- 暑假集训第三周 STL 网页浏览器
- 暑假集训第三周
- 暑假集训第三周 STL G - 487-3279
- 暑假集训第三周 STL H - Election 选举
- 暑假集训第三周 STL N - Babelfish 翻译字典
- 暑假集训 第三周 STL I - Web Navigation网页导航
- 暑假集训第三周 STL T-看病要排队
- 暑假集训第三周STL 大小写的全排列
- 2001. Scavenger Hunt
- Sicily 2001. Scavenger Hunt
- 2001. Scavenger Hunt
- poj-2491-Scavenger Hunt
- 2001. Scavenger Hunt
- 暑假集训第三周 STL J - Catch That Cow 抓捕奶牛
- 暑假集训第三周 STL S - Hat’s Words 合并单词
- undefined reference to 'pthread_create'
- Hadoop源码学习(一)
- Shell重定向&>file、2>&1、1>&2的区别
- 2015 ACM/ICPC Asia Regional Shanghai Online An easy problem(简单题)
- [LeetCode]237 Delete Node in a Linked List
- 暑假集训第三周STL L - Scavenger Hunt
- openwrt上proxy代理服务器--插入广告
- Maven(三)-依赖自己的程序
- HTML使用div和table进行布局
- 从TXT读取内容
- Linux常用命令大全
- 黑马程序员—输出函数printf和出入函数scanf
- Hive 笔记之 加载数据时,找不到文件路径异常
- 2800配置NAT实例