| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 758 人关注过本帖
标题:[求助]英文版题目(字符串)
只看楼主 加入收藏
温柔一刀
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-7-14
收藏
 问题点数:0 回复次数:8 
[求助]英文版题目(字符串)

有趣的游戏
Description
A few kids are standing around an old tree playing a game. The tree is so huge that each kid can only see the kids close to him/her.

The game consists many 'turns'. At the beginning of each turn of the game, a piece of paper is given to a randomly chosen kid. This kid writes the letter "B" if he is a boy or the letter "G" if a girl. Then he chooses a direction to pass the paper (clockwise or counter-clockwise), and gives the paper to his neighbor in that direction. The kid getting the paper writes down his sex too, and gives the paper to his neighbor in the same direction. In this way, the paper goes through the kids one by one, until one kid stops passing the paper and announces the end of this turn.

For example, there are five kids around the tree, and their genders are shown in Figure-1. The paper first goes to Kid1, after writing a "B" he passes it to Kid2, and Kid2 to Kid3. After Kid3 writes down a "G", she ends up this turn, and we get the paper with a string "BBG".

After N turns, we get N pieces of paper with strings of "B"s and/or "G"s. One of the kids will get all these papers, and has to figure out at least how many kids are around the tree playing the game. It's known that there are at least two kids. Please write a program to help him.
Input
There are several test cases. Each case starts with a line containing an integer N, the number of papers (2 <= N <= 16). Each of the following N lines contains a string on a paper, which is a nonempty string of letter "B"s and/or "G"s. Each string has no more than 100 letters.

A test case of N = 0 indicates the end of input, and should not be processed.
Output
For each test case, output the least possible number of kids in a line.
Sample Input
3
BGGB
BGBGG
GGGBGB
2
BGGGBBBGG
GBBBG
0
Sample Output
9
6

搜索更多相关主题的帖子: 英文版 字符 
2006-07-14 20:22
摄政王:多尔滚
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-7-9
收藏
得分:0 
........................

19世纪是火车的时代,20世纪是汽车的时代,21世纪是网络的时代。有谁不同意?
2006-07-14 21:20
穆扬
Rank: 1
等 级:禁止发言
帖 子:1910
专家分:0
注 册:2006-6-1
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽

2006-07-14 22:23
greatvictory
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-3-30
收藏
得分:0 

程杰?
哪里来的题?
在玩ACM?

我想到一种笨办法,但是不知道时间要求是多少。
用枚举法。首先从只有两个人开始,有四种情况:B B,G G,B G,G B,然后把得到的纸条上的字符串最长的一组的长度算出来记做A,可以想象孩子们围成一圈,从某点处断开,拉成一条直线,那么不停地传递就是这条直线不停地重复(因为方向在前面的排列组合中已经算到,就不必考虑了)。然后取这样一个重复的字符串出来记为arr,长度只要大于A即可,写一个判断字符串匹配的函数,判断纸条上的字符串是否能够匹配arr上的某一段字符串,将每张纸条的字符串都判断一下,如果全部能够匹配,那么这种情况的人数就是所求答案至少有几人。如果不行,那么3个,4个以此类推循环下去。
程序没写,也不知道这样算对不对,大家一起探讨一下!

[此贴子已经被作者于2006-7-15 18:04:32编辑过]

2006-07-15 17:05
温柔一刀
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-7-14
收藏
得分:0 
这个思想是知道的
在程序编写的时候做的太复杂了
所以四楼的
看看能不能写 一下看看
嘿嘿
算法不精啊
2006-07-16 16:00
温柔一刀
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-7-14
收藏
得分:0 

时间是越短越好

2006-07-16 16:01
秋阁
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-7-15
收藏
得分:0 

好像是ACM的题哦

2006-07-17 10:47
温柔一刀
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-7-14
收藏
得分:0 
难道都没有高手啊
没有人会解题啊
晕死
2006-07-17 20:37
温柔一刀
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-7-14
收藏
得分:0 

真的没有高手

2006-07-18 17:49
快速回复:[求助]英文版题目(字符串)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013486 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved