(简单)搜索 HOJ 1692 Choose Your Own Adventure
2014-02-08 09:53
393 查看
Choose Your Own Adventure
My Tags | (Edit) |
---|
Source : ACM ICPC South Central USA 2004 | |||
Time limit : 1 sec | Memory limit : 32 M |
Page List[/i] - A sequence of X[/i] lines, each of which represents a page from the book. Each line has the following components separated from one another by single spaces:Line type[/i] - A single character indicating what type of line this is. It will represent either a "C" choice page, or an "E" end page. Page 1 is always a choice page.
Text[/i] - A string of text surrounded by double quotes. Including the quotes, this component will not exceed 256 characters. The quotes are given for input purposes only and should not be considered part of the text. The text will not contain embedded double quotes.
Choices[/i] - Two positive integers from 1 to X[/i] indicating the pages where the reader can go from this page. Only choice pages have this component.
Ending Type[/i] - Either the text "HAPPY" or "GRISLY". There will only be one happy ending per story, and only end pages have this component.
Output[/b]For each story in the input:Output a single line, "STORY #" where # is 1 for the first story, 2 for the second story, etc.
Determine the story that begins on page 1 and ends on the happy ending page. Output the text of this story, printing one "page" of text per line. Note that there is only one such story for each data set.
Sample Input[/b]2
3
C "Arrived at LSU for the contest" 2 3
E "Was devoured by sidewalk ants" GRISLY
E "Won the contest. Received glory and nachos." HAPPY
5
C "Saw a peanut" 3 5
E "Made peanut butter sandwich" HAPPY
C "Found a hammer" 4 2
E "Hit self on head with hammer, ouch!" GRISLY
E "Ate the peanut, choked on it, and died" GRISLYSample Output[/b]
STORY 1 Arrived at LSU for the contest Won the contest. Received glory and nachos. STORY 2 Saw a peanut Found a hammer Made peanut butter sandwich
题意:有一本书,知道了某些页的内容,然后知道这一页能跳到哪一页。问怎么组织出一个happy ending ^_^
思路:直接深搜就可以了,没难度吧。
代码:#include <iostream>#include <algorithm>#include <math.h>#include <stdio.h>#include <string>#include <string.h>#include<queue>#include<set>using namespace std;#define LL long long
struct Page{ char content[256]; bool happy;}page[110];int n , ans[110] , top;bool vis[110];vector<int> G[110];
void init(){ memset(page,0,sizeof(page)); for (int i = 1 ; i <= n ; ++i) G[i].clear(); top = 0; memset(vis,0,sizeof(vis));}
char buffer[300];void input(){ for (int i = 1 ; i <= n ; ++i) { scanf("%s",buffer); if (buffer[0]=='C') { char ch = getchar(); while (ch!='"') ch = getchar(); while (scanf("%s",buffer+1)) { buffer[0] = ' '; strcat(page[i].content,buffer); if (buffer[strlen(buffer)-1]=='"') { page[i].content[strlen(page[i].content)-1]= '\0'; break; } } gets(buffer); char * p = strtok(buffer , " "); while (p) { int x; sscanf(p,"%d",&x); G[i].push_back(x); p = strtok(NULL," "); } page[i].happy = false; } else if (buffer[0]=='E') { char ch = getchar(); while (ch!='"') ch = getchar(); while (scanf("%s",buffer+1)) { buffer[0] = ' '; strcat(page[i].content,buffer); if (buffer[strlen(buffer)-1]=='"') { page[i].content[strlen(page[i].content)-1]= '\0'; break; } } scanf("%s",buffer); if (!strcmp(buffer,"HAPPY")) page[i].happy = true; else page[i].happy = false; } }}
bool dfs(int x){ if (vis[x]) return false; ans[top++] = x; if (page[x].happy) return true; vis[x] = true; for (int i = 0 ; i < G[x].size() ; ++i) { int y = G[x][i]; if (dfs(y)) return true; } --top; return false;}
void solve(){ dfs(1); for (int i = 0 ; i < top ; ++i) printf("%s\n",page[ans[i]].content+1);}
int main(){ int T; cin>>T; for (int Cas = 1 ; Cas <= T ; ++Cas) { scanf("%d",&n); init(); input(); printf("STORY %d\n",Cas); solve(); }}
题后语:非常有趣的题目。我们可以通过这种方式能得到一些意想不到,无厘头的剧情,如果以后发明了一台程序,能自动产生剧本,通过这种方式产生的话,一定会产生很搞笑的剧情。。。。可能会有些:“啊,今天天气真好,艳阳高照,细雨绵绵,我走在河道旁,突然感慨到:”这雪怎么还没消啊,真冷。“。正当我拨开厚厚的秋叶之后,拾到了一块钱的硬币,警察叔叔走了过来,取走了我的一块钱硬币,我夸这个警察叔叔是个好孩子,警察叔叔蹦蹦跳跳的上学去了。路边的清洁阿姨看着胸前的红领巾,觉得更鲜艳了。
相关文章推荐
- 搜索 HOJ 1692 Choose Your Own Adventure
- POJ 2023 Choose Your Own Adventure(树形,dfs,简单题)
- poj 2023 Choose Your Own Adventure
- poj 2023 Choose Your Own Adventure 用队列广搜 用栈深搜 用递归深搜 三种方法均测试过
- POJ_2023 Choose Your Own Adventure(DFS)
- Poj 2023 Choose Your Own Adventure
- poj 2023 Choose Your Own Adventure(数据结构+深度搜索)
- (简单) 搜索 HOJ 1044 Transportation
- (简单) 搜索 HOJ 1048 Cipher
- poj1111 hoj 1639 Image Perimeters 简单搜索
- csapp实验,一个简单的shell. Lab Assignment L5: Writing Your Own Unix Shell
- hdu 4158 hoj 2581 Go 简单搜索
- Hoj 1307 Choose Your Words Carefully、Hoj 1989 The Most Frequent Word
- (简单) 搜索 HOJ 1066 Substrings
- (简单)搜索 HOJ 1070 Word
- (简单)搜索 HOJ 1075 The Castle
- (简单) 搜索 HOJ 1085 Finding Rectangles
- Go hdu 4158 hoj 简单搜索
- (简单) 搜索 HOJ 1097 Robot
- (简单) 搜索 HOJ 1105 Egyptian Multiplication