hdu 2597 Sorted Trail Map
来源:互联网 发布:好用用打谱软件 编辑:程序博客网 时间:2024/05/19 06:50
Sorted Trail Map
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 208 Accepted Submission(s): 39
Problem Description
Volunteers from the World Wildlife Foundation (WWF) have arrived in Springfield in a WWF truck.
They are collecting endangered animals living in the nearby Gump Forest, and are asking Lisa for help.
The WWF volunteers have given Lisa a map of the Gump Forest. The forest contains a number of clearings, and trails connecting the clearings. Different types of endangered animals live on each trail, no animals live in the clearings.
The WWF are hoping to collect some endangered animals from Gump Forest. But their trail map is too confusing, since clearings and animals are listed in no particular order. Lisa decides to help the WWF volunteers by making up a sorted trail map of Gump Forest.
They are collecting endangered animals living in the nearby Gump Forest, and are asking Lisa for help.
The WWF volunteers have given Lisa a map of the Gump Forest. The forest contains a number of clearings, and trails connecting the clearings. Different types of endangered animals live on each trail, no animals live in the clearings.
The WWF are hoping to collect some endangered animals from Gump Forest. But their trail map is too confusing, since clearings and animals are listed in no particular order. Lisa decides to help the WWF volunteers by making up a sorted trail map of Gump Forest.
Input
Animals are given as words(lowercases). Clearings are given as numbers. There may be up to 500 clearings.
Clearing 0 is always the entrance to Gump Forest. The input is the unsorted Gump Forest trail map.
Each line describes a trail between two clearings as a pair of numbers, followed by a list of animals living on the trail.
Every test case ends with "-1 -1".
Clearing 0 is always the entrance to Gump Forest. The input is the unsorted Gump Forest trail map.
Each line describes a trail between two clearings as a pair of numbers, followed by a list of animals living on the trail.
Every test case ends with "-1 -1".
Output
The program output is a sorted trail map, where clearing numbers go up from 0, and animal names go from a to z. Trails are sorted by the number of the clearings at either end of the trail. All animals living on the trail are sorted in alphabetical order.
Sample Input
0 1 puma2 3 toad1 2 frog-1 -11 0 puma lynx2 0 toad1 2 vole-1 -1
Sample Output
0 1 puma1 2 frog2 3 toad0 1 lynx puma0 2 toad1 2 vole
Source
HDU 2010-05 Programming Contest
Recommend
lcy
题意:
输入 x y 之后输入未知个单词 表示一条路上(双向)有这么多个濒危动物 ,单词是这些动物的名字
输入 -1 -1 的时候 对刚才的输入进行输出
输出的时候 路径首先按照开端从小到大的顺序排列 之后按末端从小到大 而路上的动物则按照字典序进行排列
注意 对于x y, x y都可以做开端的
Trails are sorted by the number of the clearings at either end of the trail. 主要是这句话 一开始理解成了按照空地的出现个数进行排序 结果WA了好几遍
后来请教了以为大神才知道是空地的编号的意思
其实没有必要这样输入 可以先输入 x y 如果不是-1 -1 则继续gets 一下把所有单词输入 上面的做法有点麻烦了
题意:
输入 x y 之后输入未知个单词 表示一条路上(双向)有这么多个濒危动物 ,单词是这些动物的名字
输入 -1 -1 的时候 对刚才的输入进行输出
输出的时候 路径首先按照开端从小到大的顺序排列 之后按末端从小到大 而路上的动物则按照字典序进行排列
注意 对于x y, x y都可以做开端的
Trails are sorted by the number of the clearings at either end of the trail. 主要是这句话 一开始理解成了按照空地的出现个数进行排序 结果WA了好几遍
后来请教了以为大神才知道是空地的编号的意思
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<set>#include<string>#include<iostream>using namespace std;#define size 600char s[size];struct haha{ set<string>sset;}mp[size][size];void out();int main(){ int x=-100,y=-100,i,j,flag=0; while(scanf("%s",s)!=EOF) { if(s[0]>='a'&&s[0]<='z') { mp[x][y].sset.insert(s); flag=1; } else { int n=0; if(flag==1) {x=-100;y=-100;flag=0;} if(s[0]=='-') { if(x==-100) {x=-1; continue;} else { if(x==-1) { out(); x=-100; y=-100; for(i=0;i<size;i++) for(j=0;j<size;j++) mp[i][j].sset.clear(); continue; } } } i=0; while(s[i]!='\0') { n=n*10+s[i]-'0'; i++; } if(x==-100) {x=n;continue;} else y=n; if(x>y) {int temp=x;x=y;y=temp;} } } return 0;}void out(){ int i,j; set<string>::iterator it; for(i=0;i<size;i++) for(j=i;j<size;j++) { if(!mp[i][j].sset.empty()) { printf("%d %d",i,j); for(it=mp[i][j].sset.begin();it!=mp[i][j].sset.end();it++) cout<<" "<<*it; printf("\n"); } }}
其实没有必要这样输入 可以先输入 x y 如果不是-1 -1 则继续gets 一下把所有单词输入 上面的做法有点麻烦了
- hdu 2597 Sorted Trail Map
- 【博弈论】RacingCar Trail trail
- map,reduce,sorted的用法
- Almost Sorted Array HDU
- EJB trail
- oak trail
- Trail: RMI
- Freedom Trail
- python中的map,reduce,filter,sorted函数
- python学习笔记,map/reduce,filter,sorted
- python基础之map/reduce/filter/sorted
- 高阶函数:map、reduce、filter、sorted
- hdu 5532 Almost Sorted Array
- HDU 5532 Almost Sorted Array
- HDU 5532 Almost Sorted Array
- 【HDU】 5532 Almost Sorted Array
- HDU 5532 Almost Sorted Array
- HDU 5532:Almost Sorted Array
- 关于写程序的一个经验
- 所有函数都有的方法:apply()和call()
- windows常用命令行命令
- 如何在单击label标签时让文本框获得焦点?
- 使用工具 autoconf 和automake 自动创建 Makefile
- hdu 2597 Sorted Trail Map
- 字符串化的预处理器
- SPOJ3899 Finding Fractions
- winmail 完美破解版
- fieldset的作用
- 字符集和字符编码(Charset & Encoding)
- 贪心算法
- 数据库原理
- 余凯老师发表的:深度学习: 推进人工智能的梦想