首页 > ACM题库 > HDU-杭电 > hdu 2171 “Bubble Gum, Bubble Gum, in the dish, how many pieces do you wish?”待解决[解题报告]C++
2013
12-30

hdu 2171 “Bubble Gum, Bubble Gum, in the dish, how many pieces do you wish?”待解决[解题报告]C++

“Bubble Gum, Bubble Gum, in the dish, how many pieces do you wish?”

问题描述 :

Alex and Karyn were at it again. The elementary school sisters were playing their favorite game to decide who gets to play on the computer next.

The rules of the game are quite simple. Given p people (p > 0), one of the p people is chosen to pick a number n (n > p) representing the number of pieces of bubble gum desired. Once this value is chosen, the people are iterated through, one at a time, starting at 1, from “left” to “right”, starting with the person who chose the number. Iterating is done in a circular fashion, meaning that once the person on the far right is reached, the next person in the iteration will be the person on the far left. Upon reaching n, the person at that location is the winner.

Given a list of names, followed by the name of the person choosing the number of pieces of bubble gum, followed by the number that person chose, determine who wins the game.

输入:

The first value in the input file will be an integer t (0 < t < 1000) representing the number of test cases in the input file. Following this, on a case by case basis, will be a list of the names of the people (p), on a single line. Names will be no larger than 20 characters in length and all names are unique. There will be no more than 20 names. Each name is followed by a space, save for the last name, which is followed by a newline. On the next line is the name of the person choosing the number of pieces of bubble gum, followed by a newline. The test case is concluded with the number of pieces of gum n (p < n < 1000), which is also followed by a newline.

输出:

The first value in the input file will be an integer t (0 < t < 1000) representing the number of test cases in the input file. Following this, on a case by case basis, will be a list of the names of the people (p), on a single line. Names will be no larger than 20 characters in length and all names are unique. There will be no more than 20 names. Each name is followed by a space, save for the last name, which is followed by a newline. On the next line is the name of the person choosing the number of pieces of bubble gum, followed by a newline. The test case is concluded with the number of pieces of gum n (p < n < 1000), which is also followed by a newline.

样例输入:

3
Alex Karyn Maude
Karyn
5
Alex Karyn Maude
Alex
6
Alex Karyn Zach Becca Maude
Zach
8

样例输出:

Maude
Maude
Maude


  1. 第二块代码if(it != mp.end())应改为if(it != mp.end() && (i+1)!=(it->second +1));因为第二种解法如果数组有重复元素 就不正确

  2. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。