当前位置: 首页 > news >正文

桥头镇网站建设易观数据

桥头镇网站建设,易观数据,想自己做个网站怎么做,太平洋电脑网站目录 第一题: L2-003 月饼 输入格式: 输出格式: 输入样例: 输出样例: 题目分析 题目代码 第二题:德才论 输入格式: 输出格式: 输入样例: 输出样例&#xff…

目录

第一题: L2-003 月饼

输入格式:

输出格式:

输入样例:

输出样例:

题目分析

题目代码

 第二题:德才论  

输入格式:

输出格式:

输入样例:

输出样例:

题目分析

思路:

题目代码


第一题: L2-003 月饼

月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。

注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有 3 种月饼,其库存量分别为 18、15、10 万吨,总售价分别为 75、72、45 亿元。如果市场的最大需求量只有 20 万吨,那么我们最大收益策略应该是卖出全部 15 万吨第 2 种月饼、以及 5 万吨第 3 种月饼,获得 72 + 45/2 = 94.5(亿元)。

输入格式:

每个输入包含一个测试用例。每个测试用例先给出一个不超过 1000 的正整数 N 表示月饼的种类数、以及不超过 500(以万吨为单位)的正整数 D 表示市场最大需求量。随后一行给出 N 个正数表示每种月饼的库存量(以万吨为单位);最后一行给出 N 个正数表示每种月饼的总售价(以亿元为单位)。数字间以空格分隔。

输出格式:

对每组测试用例,在一行中输出最大收益,以亿元为单位并精确到小数点后 2 位。

输入样例:

3 20
18 15 10
75 72 45

输出样例:

94.50

代码长度限制

16 KB

时间限制

150 ms

内存限制

64 MB

题目分析

  •  一个元素有多个属性就想到构造类

  • 构造类用来存相应的属性可以重新定义一下排序的方法即compareTo()方法                    

题目代码

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;public class 月饼 {static PrintWriter out = new PrintWriter(System.out);static BufferedReader ins = new BufferedReader(new InputStreamReader(System.in));static StreamTokenizer in = new StreamTokenizer(ins);static class YueBing implements Comparable<YueBing> {double kucun;double sum_price;double one_price;public YueBing(double kucun, double sum_price) {this.kucun = kucun;this.sum_price = sum_price;this.one_price = sum_price / kucun;}@Overridepublic int compareTo(YueBing o) {if (o.one_price - this.one_price > 0)return 1; //降序排列else return -1;}}public static void main(String[] args) throws IOException {in.nextToken();int n = (int) in.nval;in.nextToken();int xuqiu = (int) in.nval;String[] s1 = ins.readLine().split(" ");String[] s2 = ins.readLine().split(" ");double res = 0;ArrayList<YueBing> list = new ArrayList<>();for (int i = 0; i < n; i++) {list.add(new YueBing(Double.parseDouble(s1[i]), Double.parseDouble(s2[i])));}Collections.sort(list);for (int i = 0; i < n; i++) {if (list.get(i).kucun >= xuqiu) {res += xuqiu * list.get(i).one_price;break;} else {res += list.get(i).sum_price;xuqiu -= (int)list.get(i).kucun ;}}System.out.printf("%.2f",res);}
}

 第二题:德才论  

宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”

现给出一批考生的德才分数,请根据司马光的理论给出录取排名。

输入格式:

输入第一行给出 3 个正整数,分别为:N(≤105),即考生总数;L(≥60),为录取最低分数线,即德分和才分均不低于 L 的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到优先录取线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于 H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线 L 的考生也按总分排序,但排在第三类考生之后。

随后 N 行,每行给出一位考生的信息,包括:准考证号 德分 才分,其中准考证号为 8 位整数,德才分为区间 [0, 100] 内的整数。数字间以空格分隔。

输出格式:

输出第一行首先给出达到最低分数线的考生人数 M,随后 M 行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。

输入样例:

14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60

输出样例:

12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90

题目分析

思路:

  • 构造类存储属性

  • 将不同类别进行区分存储再排序

题目代码

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;public class 德才论 {static PrintWriter out = new PrintWriter(System.out);static BufferedReader ins = new BufferedReader(new InputStreamReader(System.in));static StreamTokenizer in = new StreamTokenizer(ins);static class Person implements Comparable<Person> {int no;int de_core;int cai_core;int sum_core;public Person(int no, int de_core, int cai_core) {this.no = no;this.de_core = de_core;this.cai_core = cai_core;this.sum_core = de_core + cai_core;}// 此类考生按德才总分从高到低排序  (降序)// 当某类考生中有多人总分相同时,按其德分降序排列;// 若德分也相同,则按准考证号的升序输出@Overridepublic int compareTo(Person o) {if (o.sum_core != this.sum_core) {return o.sum_core - this.sum_core;//降序排列:当左边的this.sum_core小于o.sum_core时返回1 交换俩者的位置;} else if (de_core != cai_core) {return o.de_core - this.de_core;//降序排列} else return this.no - o.no;//升序排列}}public static void main(String[] args) throws IOException {in.nextToken();int n = (int) in.nval;in.nextToken();int l = (int) in.nval;in.nextToken();int h = (int) in.nval;ArrayList<Person> list1 = new ArrayList();//存第一类人ArrayList<Person> list2 = new ArrayList();//存第二类人ArrayList<Person> list3 = new ArrayList();//存第三类人ArrayList<Person> list4 = new ArrayList();//存第四类人int res = 0;while (n-- > 0) {//输入数据String[] split = ins.readLine().split(" ");int a = Integer.parseInt(split[0]);//noint b = Integer.parseInt(split[1]);//de_coreint c = Integer.parseInt(split[2]);//cai_coreif (b >= l && c >= l) {res++;if (b >= h && c >= h) {list1.add(new Person(a, b, c));} else if (b >= h && c < h) {list2.add(new Person(a, b, c));} else if (b >= c && c < h && b < h) {list3.add(new Person(a, b, c));} else {list4.add(new Person(a, b, c));}}}Collections.sort(list1);//排序Collections.sort(list2);Collections.sort(list3);Collections.sort(list4);out.println(res);//输出for (int i = 0; i < list1.size(); i++) {out.println(list1.get(i).no + " " + list1.get(i).de_core + " " + list1.get(i).cai_core);}for (int i = 0; i < list2.size(); i++) {out.println(list2.get(i).no + " " + list2.get(i).de_core + " " + list2.get(i).cai_core);}for (int i = 0; i < list3.size(); i++) {out.println(list3.get(i).no + " " + list3.get(i).de_core + " " + list3.get(i).cai_core);}for (int i = 0; i < list4.size(); i++) {out.println(list4.get(i).no + " " + list4.get(i).de_core + " " + list4.get(i).cai_core);}out.flush();}
}

http://www.yidumall.com/news/53711.html

相关文章:

  • 太原做网站设计广州网站推广服务
  • 龙溪网站建设企业企业建站 平台
  • 幸福人寿保险公司官方网站免费制作网站的软件
  • 马克 扎克伯格大学做的网站百度推广营销页
  • 兰州网站建设公做网站的好处
  • 凡科做的网站百度不到友链外链app
  • 如何做网站seo优化seo优化在哪里学
  • 网站可以做多少个关键词网站开发的步骤
  • 网站颜色表株洲百度seo
  • 泰安企业网站建设博客营销
  • 做视频网站资质aso关键词搜索优化
  • 滨州网站网站建设上海百度推广优化公司
  • java jsp网站开发购买域名的网站
  • 红色为主的网站惠州seo全网营销
  • 安防网站建设优点世界搜索引擎大全
  • 网站300兆是多少钱青岛的seo服务公司
  • 电子商务网站建设与管理期末考试网络营销的目的是什么
  • 电子商务网站开发教程课后习题公司软文代写
  • 成都自由行攻略最详细泰州百度seo公司
  • 动态网站建设课程百度首页广告多少钱
  • 网站制作素材河源今日头条新闻最新
  • 外贸网站和内贸中国新闻网
  • dedecms win8风格网站模板seo排名点击软件
  • 郑州炫彩网站建设在线网站排名工具
  • 动画网站欣赏广州做seo公司
  • 青海企业网站建设开发在线网页制作系统搭建
  • solaris.wordpress太原seo快速排名
  • web开发兼职网站开发如何创建网址
  • 贵州建设工程招标协会网站口碑营销成功案例
  • 网站开发职责个人网站模板建站