[Detailed Explanation of the Real Questions of the Blue Bridge Cup JavaB Group] Martial Arts Cheats (2014)

Title description

Martial Arts Cheats
Xiao Ming went to X Cave to explore, and found a damaged martial arts Cheats (more than 2000 pages! Of course it is forged).
He noticed that the 10th and 11th pages of the book are on the same paper, but the 11th and 12th pages are not on the same paper.
Xiao Ming only wants to practice martial arts from page 81 to page 92 of the book, but doesn't want to bring the whole book. May I ask how many pieces of paper he must tear off at least to take away?
This is an integer, please submit the number through your browser, and do not fill in any extra content.

Problem solving ideas

This is a warm-up question. The 10th and 11th pages of the book are on the same paper. It is easy to get that the 80th and 81st pages of the book are on one piece of paper. Soon you can get 7 pieces of paper.
If this problem is over in the game, but if the value is relatively large or tricky, it will take up a certain amount of time for us, so we can also find out the rules and write programs.
Reference Code

import java.util.Scanner;
 
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner input = new Scanner(System.in);
		int a=input.nextInt();
		int b=input.nextInt();
		int count;
		if (a%2!=0&b%2==0){
    
    
			count=(b-a)/2+2;
		}
		else{
    
    
			count=(b-a)/2+1;
		}
		System.out.println(count);	
	}

Novice creation and learning, if there are mistakes, please give pointers, thank you!

Guess you like

Origin blog.csdn.net/m0_46226318/article/details/113208945