POJ 2708:平衡饮食

AC CODE :

原题连接

 1 import java.util.Scanner;
 2 
 3 
 4 public class Main {
 5 
 6     private static int[] getDatas() {
 7         Scanner input = new Scanner(System.in);
 8         int[] datas = new int[10];
 9         for (int i = 0; i < 10; i++) {
10             datas[i] = input.nextInt();
11         }
12         return datas;
13     }
14     
15     private static boolean judgeData(int[] datas) {
16         double[][] nutrient = new double[10][3];
17         nutrient = getNutrientContent();
18         double[] energy = {4.1, 9.3, 4.1};
19         
20         double[][] energyTable = getEnergyTable(datas, nutrient, energy);
21         double[] PFC = {0, 0, 0};
22         for (int i = 0; i < 3; i++) {
23             for (int j = 0; j < 10; j++) {
24                 PFC[i] += energyTable[j][i];
25             }
26         }
27         
28         double[] rates = {0, 0, 0};
29         for (int i = 0; i < 3; i++) {
30             rates[i] = (PFC[i] / (PFC[0] + PFC[1] + PFC[2])) * 100;
31         }
32         
33         if ((14 > rates[0]) || (rates[0] > 16)) {
34             return false;
35         }
36         if ((30 > rates[1]) || (rates[1] > 35)) {
37             return false;
38         }
39         if ((49 > rates[2]) || (rates[2] > 56)) {
40             return false;
41         }
42         
43         return true;
44     }
45     
46     private static double[][] getEnergyTable(int[] datas, double[][] nutrient, double[] energy) {
47         double[][] energyTable = new double[10][3];
48         for (int i = 0; i < 10; i++) {
49             for (int j = 0; j < 3; j++) {
50                 energyTable[i][j] = nutrient[i][j] * datas[i] * energy[j];
51             }
52         }
53         return energyTable;
54     }
55     
56     private static double[][] getNutrientContent() {
57         double[][] nutrient = new double[10][3];
58         for (int i = 0; i < 10; i++) {
59             for (int j = 0; j < 3; j++) {
60                 nutrient[i][j] = getContent()[i * 3 + j];
61             }
62         }
63         return nutrient;
64     }
65     
66     private static double[] getContent() {
67         double[] nutrient = {
68                 7.5,0.75,78,
69                 10,1.25,75,
70                 1.5,0.19,4.28,
71                 35,18,42,
72                 5.0,5.0,0.6,
73                 16.5,28.8,1.05,
74                 17.7,20.33,4.06,
75                 14.9,0.8,0.93,
76                 0,100,0,
77                 0.85,0.5,8
78         };
79         return nutrient;
80     }
81     
82     public static void main(String[] args) {
83         int[] datas = getDatas();
84         if (judgeData(datas)) {
85             System.out.println("yes");
86         }else {
87             System.out.println("no");
88         }
89     }
90 
91 }

 

你可能感兴趣的:(poj)