zoukankan      html  css  js  c++  java
  • 搜狐_笔试_题目二

    import java.util.*;
    /*
     * 题目
        工厂生产的产品包装在相同高度h,尺寸为1*1,2*2,3*3,4*4,5*5,6*6的方形包装中.
        这些产品始终以与产品高度相同的尺寸为6*6的包裹交付给客户.
        因为邮费很贵,所以工厂要想方设法地减少每个订单运送时的包裹数量.
        他们很需要有一个好的程序员帮他们解决这个问题从而节省费用.
        现在这个程序由你来设计.
        输入
        
        输入文件包括几行,每一行代表一个订单.
        每个订单里的一行包括六个整数,中间用空格隔开,分别为1*1至6*6这六种产品的数量.
        输入文件将以6个0组成一行结尾.
        输出
        
        除了输入的最后一行6个0以外,输入文件里每一行对应着输出文件一行,每一行输出一个整数代表对应订单所需的最小包裹数.
        Example
        
        Input
        
        0 0 4 0 0 1
        7 5 1 0 0 0
        0 0 0 0 0 0  
        Output
        
        2
        1
     */
    public class Sohu_two {
        public static void getArr(int m, int n, int[][] a) {
            int[] b = new int[m];
            
            for(int i = 0; i < m; i++) {    
                int count = 0;
                if(a[i][5] > 0) count += a[i][5];
                if(a[i][4] > 0) {
                    count += a[i][4];
                    if(a[i][0] <= a[i][4] * 11) {
                        a[i][0] = 0;
                    } else {
                        a[i][0] -= a[i][4] * 11;
                    }
                }
                if(a[i][3] > 0) {
                    count += a[i][3];
                    if(a[i][1] <= a[i][3] * 5) {
                        a[i][1] = 0;
                        if(a[i][0] <= a[i][3] * (20 - a[i][1] * 4)) {
                            a[i][0] = 0;
                        } else {
                            a[i][0] -= a[i][3] * (20 - a[i][1] * 4);
                        }
                    } else {
                        a[i][1] -= a[i][3] * 5;
                    }
                }
                if(a[i][2] > 0) {
                    if(a[i][2] % 4 != 0) {
                        count += a[i][2] / 4 + 1;
                        if(a[i][1] * 4 <= (36 - a[i][2] % 4 * 9)) {
                            int temp = 36 - a[i][2] % 4 * 9 - a[i][1] * 4; 
                            a[i][1] = 0;
                            if(a[i][0] <= temp) {
                                a[i][0] = 0;
                            } else {
                                a[i][0] -= temp; 
                            }
                        } else {
                            a[i][1] -= (36 - a[i][2] % 4 * 9) / 4;
                        }
                    } else  count += a[i][2] / 4;
                    
                }
                if(a[i][1] > 0) {
                    if(a[i][1] % 9 == 0) {
                        count += a[i][1] / 9;
                    } else {
                        count += a[i][1]/9;
                        int temp = a[i][1] % 9 * 4;
                        if(a[i][0] <= (36 - temp)) {
                            count += 1;
                        } else {
                            count += 1;
                            a[i][0] -= 36 - temp;
                        }
                    }
                }
                if(a[i][0] > 0) {
                    if(a[i][0] % 36 == 0) {
                        count += a[i][0] / 36;
                    } else count += a[i][0] / 36 + 1;
                }
                System.out.println(count);
            }            
        }
        
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int m = 2;
            int n = 6;
            int[][] a = new int[m+1][n];
            for(int i = 0; i < m+1; i++) {
                for(int j = 0; j < n; j++) {
                    a[i][j] = in.nextInt();
                }
            }
            
            getArr(2,6,a);
        }
    
    }
  • 相关阅读:
    事物的五种配置方式(转载)
    Spring入门
    leetcode刷题3
    LeetCode刷题2
    LeetCode刷题1
    bootstraptable使用总结之前端样式设计
    初识Handsontable
    Java之file类
    OpenCV学习系列教程第五篇:测试和提高代码的效率
    OpenCV学习系列教程第四篇:图像的算术操作
  • 原文地址:https://www.cnblogs.com/zzsaf/p/7447720.html
Copyright © 2011-2022 走看看