CCF the game of Real title (_1712_2_game.java)

Source: Internet
Author: User

CCF the game of Real title (_1712_2_game.java)

Problem Description:

Question number: 201712-2
Question Name: Game
Time limit: 1.0s
Memory Limit: 256.0MB
Problem Description: Problem description There are N children playing games around in a circle, children from 1 to n numbered, number 2nd children sitting in the clockwise direction of 1th children, 3rd children sitting in the clockwise direction of 2nd children, ..., 1th children sitting in the clockwise direction of the number N children.
The beginning of the game, from the number 1th children began to count clockwise, the next one of the children's number is a child reported a few plus 1. If a child reported a multiple of K or its last number (that is, the number of digits) for K, then the child was eliminated, no longer participate in the next 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 numbered 1;
2nd number of children numbered 2 out of the elimination;
3rd Number of children numbered 3;
4th Number of children numbered 4 out of the elimination;
5th number of children numbered 5;
1th number of children numbered 6 out of the elimination;
3rd Number of children numbered 7;
5th number of children numbered 8 out of the elimination;
Child number 3rd wins.

Given N and K, what is the number of the last child to win? Enter a line of input format, including two integers n and K, meaning as described in the topic. Output format output line, contains an integer, indicating the number of the child won. Sample Input 5 2 sample Output 3 Sample input 7 3 sample output 4 data scale and conventions for all evaluation use cases, 1≤n≤1000,1≤k≤9.

Reference code:

Package com.test;

Import java.util.ArrayList;
Import Java.util.Scanner;

/**
 * * 
 @Author: Dina
 * @Time: January 13, 2018 
 * @Description: Game
 * @Score: 100 min
/public class _1712_2_game {public

	static void Main (string[] args) {	
		Scanner src=new Scanner (system.in);
		int N=src.nextint ();
		int K=src.nextint ();
		int yu=0, j=0;		
		arraylist<integer> list = new arraylist<integer> ();		
		for (int i = 1; i < n+1 i++) {
			list.add (i);
		}		
		for (int i = 0; i < list.size (); i++) {		
			j=i+1;
			
			while (j>10) {	//processing number of the reported number greater than 10		
				yu=j%10;
				J=yu;
			}
			j=i+1;
			The number of the newspaper is not a multiple of k and its bottom number (that is, number of digits) is not k, then the child will not be eliminated, continue to participate in the future of the Count
			if ((j%k!=0) && (yu!=k) && (j!=k)) {
				List.add (List.get (i));
			}		
		System.out.println (List.get (List.size ()-1));
		Src.close ();
	}



Submission is available by:


Related Article

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.