CCF Game Python implementation (201712-2)

Source: Internet
Author: User

First, the original question

Problem Description
question number: 201712-2
question name: game
1.0s
256.0MB
Problem Description: Problem DescriptionYesNA child in a circle to play games, children from 1 toNNo. 2nd children sitting in the clockwise direction of the number 1th children, 3rd children sitting in the clockwise direction of the number 2nd children, ..., 1th children sitting inNNumber of children in the clockwise direction.
The game began, from 1th children began to count clockwise, and then each of the children's number is the last child reported a few plus 1. If a child reported the number ofkThe number of digits or digits of thek, the child is eliminated from the game, no longer participate in the future count. When there is only one child left in the game, the child wins.
For example, when n=5, k=2:
1th number of children 1;
2nd number of children 2 out of the elimination;
3rd number of children 3;
4th Number of children 4 out of the elimination;
5th number of children 5;
1th Number of children 6 out of the elimination;
3rd number of children 7;
5th number of children 8 out of the elimination;
Child number 3rd wins.

GivenNAndk, what is the number of the last winning children?Input FormatEnter a row, including two integersNAndk, meaning as described in the title.output FormatThe output line contains an integer that represents the winning child number.Sample Input5 2Sample Output3Sample Input3 ·Sample Output4data size and conventionsFor all evaluation cases, 1≤ N ≤1000,1≤ k ≤9.

Second, the

Use up to two lists and a counter. The counter is used to record the current child's count. The first list is for children without a count. The second list is used to pack a number and is not an integer multiple of K's child. When the first list is finished looping over, the second list is copied back to the first list. Then the second list is empty. And then loop it twice. When the first list length is 1 o'clock, the loop stops. Then output the number of the current child.

Note: When you build with range, Python3 is generating an iterator. So you need to use list to actually generate this list in memory. Then there is the number of each element of the list that corresponds to the child should be this digit plus 1 is the real number of the child.

Third, the Code

20 points are submitted below: L = List (map (Int,input (). Split ())) n, k = l[0], L[1]li = list (range (n)) C = 1while len (li) > 1:    li1 = []    For I in range (Len (LI)):        if c%k==0:            c + = 1        else:            li1.append (Li[i])            c + = 1    li = Li1[:]print (li[0] +1)

CCF Game Python implementation (201712-2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.