当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1346:Board of Directors Meeting

题目描述
Meetings of board of directors of a company are held in a specially designed room. The room contains a central table in the form of a ring around which revolving chairs are placed. There is an entry to approach the center of the ring where there is a single revolving chair. An outline of the arrangement inside the room is shown in the figure below.



The following protocol is maintained during the meeting:

1. The total number of members present in any meeting is an even number, say, 2N, where 5<2N<25. The members are identified by integers 1,2,...,2N.

2. Around the table N blue and N red chairs are placed alternately for the members to sit. Arrangements of blue and red chairs are considered circular. Thus the entry path does not affect the proximity of chairs on two sides of the path. At the start of the meeting 2N members sit on 2N chairs around the table.

3. In addition to the N blue and N red chairs one white chair is placed at the center of the table. When the white chair is vacant a member occupying a red chair only, may vacate the red chair and sit on the white chair to address the meeting.

4. During an address one blue / red chair always remains vacant. A member seated on either side of the vacant chair may vacate her / his chair and occupy the vacant chair. This type of change of chairs may be made by members any number of times during an address.

5. After completion of an address a member vacates the white chair and occupies the blue / red chair vacant at that time.

Reporters are briefed at the beginning and at the end of the meeting. However they are not supplied with all the details they wish to know. A reporter is curious to know the total number of addresses delivered in the meeting. He notes down the relative positions of members in anticlockwise order with respect to the member identified by the integer 1, at the beginning as well as at the end of the meeting.

You are required to write a computer program to find the minimum number of addresses delivered during the meeting.

输入解释
The input may contain multiple test cases.

For each test case there are three input lines. The first line contains two integers, the case number c and the total number of member 2N.

The next two lines consist of two strings giving the relative position of members at the beginning and at the end of the meeting, in anticlockwise order with respect to the member 1.

Each input string starts with a letter-integer combination (without any blank between the letter and the integer) either B1 (if member 1 is on a blue chair) or R1 (if member 1 is on a red chair) and is followed by a permutation of integers 2, 3, � 2N. A blank character precedes each integer appearing in the string, with the exception of 1. The input is illustrated in sample input.

The input terminates with an input 0 for c.
输出解释
For each test case in the input print in one line two integers c and m separated by a blank character. The integer c is the test case number and m is the minimum number of addresses delivered in the meeting.
输入样例
1 6 
B1 3 6 5 4 2 
R1 3 6 5 4 2 
2 6 
B1 3 6 5 4 2 
R1 3 4 6 5 2 
0 
输出样例
1 1 
2 2 

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 kanpur 2002

源链接: POJ-1346

最后修改于 2020-10-29T06:01:32+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000