CCF CSP soy sauce java 201709_1 100 points

CCF CSP soy sauce java 201709_1 100 points

Problem Description
  Xiao Ming with N dollars to buy soy sauce. Soy sauce bottle 10 dollars, the merchant promotions, every buy 3 bottles get a bottle, or bought each 5 bottles get 2 bottles. Ask how much a bottle of soy sauce Xiao Ming can get up to.
Input format
  of the first line of the input contains an integer N, the amount of money available for Bob to buy soy sauce. 10 is an integer multiple of N, N does not exceed 300.
Output format
  output an integer representing the number of bottles of soy sauce Xiao Ming can get up to.
Input Sample
  40
Sample Output
  5
Example Description
  The 30 and $ 40 dollar is equal to $ 10, buy a bottle 3 and bottles, respectively, wherein a feeding bottle 3 bottles, 5 bottles were obtained.
Input Sample
  80
Sample Output
  11
sample shows
  the 30 and $ 80 dollar is equal to 50, 5 to buy 3 bottles and bottles, respectively, wherein a feeding bottle 3 bottles, 5 bottles feeding bottles 2, to give a total of 11 bottles.
Analysis
  of this question, although very simple, but the idea is very important. Greedy algorithm is a classic algorithm. Interested parties can understand the next. On this question, this is definitely the first five bottles 5 bottle buy, then buy 3 bottles 3 bottles, the rest to buy a bottle of 1 bottle. Such buy soy sauce is definitely the most.
Java code is as follows

import java.util.Scanner;
public class csp201709_1 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int number = input.nextInt();
		int count1 = number / 50;
		number = number % 50;
		int count2 = number / 30;
		number = number % 30;
		int count3 = number / 10;
		int result = 7 * count1 + 4 * count2 + count3;
		System.out.println(result);
	}

}

ok! I'm done, if you have other methods or problems, please share in the comments area.

Published 19 original articles · won praise 13 · views 4075

Guess you like

Origin blog.csdn.net/qq_38929464/article/details/88586037