zoukankan      html  css  js  c++  java
  • 1070milk

    总体思路是 先找出每一瓶牛奶的有效天数是多少 例如 500 就是 两天 ,1000 就是 五天 10000有效牛奶量1000 也就是五天
    然后判断那个有效天数所对应的价格最低
    ps 里面涉及到除法 所以用double保存 除非要取整数部分 就不用

    import java.util.Scanner;
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		while (sc.hasNext()) 
    		{
    			int t = sc.nextInt();
    			while (t > 0) 
    			{
    				int num = sc.nextInt();
    				String name[] = new String[num];
    				int val[][] = new int[num][3];
    				double compare [] = new double[num];
    				int temp = 0;
    				for (int i = 0; i < num; i++) 
    				{
    					name[temp] = sc.next();
    					val[temp][0] = sc.nextInt();// money9
    					val[temp][1] = sc.nextInt();// ml
    					//值要大于200 才是有效值
    					if (val[temp][1] >= 200) 
    					{
    						//有效天数
    						val[temp][2] = val[temp][1] / 200;// day
    						if (val[temp][2] >= 6) {
    							val[temp][2] = 5;
    						}
    						compare[temp] = (val[temp][0]*1.0 / val[temp][2]);//compare
    						temp++;
    					}
    				}
    //double 类型数之间的比较
    				int p = 0;
    				double flag = compare[0];
    				for (int i = 1; i < temp; i++) 
    				{
    					if (flag - compare[i] > 1e-6){
    						p = i ;
    						flag = compare[i];
    					}
    					else if(compare[i] - flag > 1e-6) {}
    					
    					else if (Math.abs(flag - compare[i])  <= 1e-6)
    					{
    						if (val[p][1] < val[i][1]) 
    						{
    							p = i;
    						}
    					}
    				}
    				System.out.println(name[p]);
    				t--;
    			}
    		}
    	}
    }
    
  • 相关阅读:
    sb#run():
    aop编程,自定义注解参数和方法范围
    vue 工程化
    mybatis SqlSession
    java传时间
    树的同构
    串的模式匹配
    堆栈模拟队列
    银行业务队列简单模拟
    一元多项式的乘法与加法运算
  • 原文地址:https://www.cnblogs.com/cznczai/p/11150193.html
Copyright © 2011-2022 走看看