• Java实现 洛谷 P2089 烤鸡


    在这里插入图片描述

    import java.util.Arrays;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Scanner;
     
    public class Main {
    	private static Scanner cin;
    	private static LinkedList<String> list;
    	private static int max;
    	private static int[] condiments = new int[10];
    	
    	public static void main(String args[]) throws Exception {
    		cin = new Scanner(System.in);
    		max = cin.nextInt();
    		if(max<10 || max>30) {
    			System.out.println("0");
    			return;
    		}
    		list = new LinkedList<String>();
    		Arrays.fill(condiments, 0);
    		for(int i=1;i<=3;i++) {
    			condiments[0] = i;
    			calc(i,9);
    		}
    		
    		if(list.size()<=0) {
    			System.out.println("0");
    		}else {
    			System.out.println(list.size());
    			Iterator<String> is = list.iterator();
    			while(is.hasNext()) {
    				String value = (String)is.next();
    				System.out.println(value);
    			}
    		}
    	}
     
    	public static void calc(int sum, int n) {
    		if(n>0) {
    			for(int i=1;i<=3;i++) {
    				if(sum+i>max) {
    					return;
    				}else if(sum+i==max && n==1){
    					condiments[9] = i;
    					
    					list.add(String.format("%d %d %d %d %d %d %d %d %d %d", condiments[0],condiments[1],condiments[2],
    							condiments[3],condiments[4],condiments[5],condiments[6],condiments[7],condiments[8],condiments[9]));
    				}else {
    					condiments[9-n+1] = i;
    					calc(sum+i,n-1);
    				}
    			}
    		}
    	}
    	
    }
    
  • 相关阅读:
    婚姻中媒人存在的客观逻辑——leo鉴书45
    为什么要使用RTP
    OCP-1Z0-053-200题-148题-485
    OCP-1Z0-053-200题-149题-78
    OCP-1Z0-053-200题-150题-236
    OCP-1Z0-053-200题-151题-53
    OCP-1Z0-053-200题-152题-56
    OCP-1Z0-053-200题-153题-211
    OCP-1Z0-053-200题-154题-208
    OCP-1Z0-053-200题-155题-218
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12947131.html
Copyright © 2020-2023  润新知