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--;
    			}
    		}
    	}
    }
    
  • 相关阅读:
    solr中facet、group查询
    Solr开发文档
    Java的Properties类和读取.properties文件
    CentOS RPM安装MySQL-5.6
    C#中的 IList, ICollection ,IEnumerable 和 IEnumerator
    Linq to Xml
    Linq查询
    XDocument和XmlDocument的区别
    关于扩展方法
    今天刚刚开通了园子
  • 原文地址:https://www.cnblogs.com/cznczai/p/11150193.html
Copyright © 2011-2022 走看看