C-1
来源:互联网 发布:php代理商系统源码 编辑:程序博客网 时间:2024/05/22 08:02
Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.Mary has accomplished many great projects, one of which is the Guanghua Building. The public opinion is that Guanghua Building is nothing more than one of hundreds of modern skyscrapers recently built in Shanghai, and sadly, they are all wrong. Blue.Mary the great civil engineer had try a completely new evolutionary building method in project of Guanghua Building. That is, to build all the floors at first, then stack them up forming a complete building. Believe it or not, he did it (in secret manner). Now you are face the same problem Blue.Mary once stuck in: Place floors in a good way. Each floor has its own weight w i and strength s i. When floors are stacked up, each floor has PDV(Potential Damage Value) equal to (Σw j)-s i, where (Σw j) stands for sum of weight of all floors above. Blue.Mary, the great civil engineer, would like to minimize PDV of the whole building, denoted as the largest PDV of all floors. Now, it’s up to you to calculate this value.
310 62 35 422 22 2310 32 53 3
102
题目大意:现在给你N块板子,每一块木板都有着两个属性,一个是重量w,另一个是承受力s,同时每一块木板会有一个pdv数值,计算方法为(Σw j)-s i,即所有在其上的木板的重量之和减去他的承受力,问你怎么样放置才能使pdv的最大值(pdv最大的那块木板)最小。思路分析:首先,题目要求的是pdv最大的那块木板的pdv值,并不是让所有木板的pdv之和最小,读题时一定要注意!另外,很显然我们需要对这些木板进行排序,但是我们应该怎么排才能使最大的pdv值最小呢?换言之,我们以什么样的标准来决定哪块木板在上,哪块木板在下。对于相邻放置的两块板,设两块板为i,j他们上面的重量为sum1) a=sum-si;b=sum+wi-sj;交换两个板的位置
2)a'=sum+wj-si;b'=sum-sj;
如果1优于2,求解得有效的条件为wj-si>wi-sj
即wj+sj>wi+si
所以按si+wi的和排序贪心即可。
package lanqiaobei;import java.util.*;public class Main { static Scanner in =new Scanner(System.in); static Comparator<Floor> com=new Comparator<Floor>() {@Overridepublic int compare(Floor o1, Floor o2) {return (o1.s+o1.w)-(o2.s+o2.w);}};public static void main(String[] args) {while(in.hasNext()){ int n = in.nextInt(); int w,s; List<Floor> st=new ArrayList<Floor>();for (int i = 0; i < n; i++) {w=in.nextInt();s=in.nextInt(); Floor f = new Floor(w,s); st.add(f);}Collections.sort(st,com);int sum=0,max=0,t;sum=st.get(0).w;for (int i = 1; i <n; i++) {t=sum-st.get(i).s;if(t>max)max=t;sum+=st.get(i).w; }if(sum-st.get(st.size()-1).s>=0) System.out.println(max);else System.out.println(0); }}}class Floor{int w;int s;Floor(int w,int s){this.w=w;this.s=s;}}
阅读全文
0 0
- c/c++--1
- C-1-C基础
- 求1+2+...+n[C/C++/C#]
- C&C++(1) - extern "C"的作用
- C#:1
- c++[1]
- C++#1
- C#(1)
- C.1
- C 1
- c++(1)
- C - 1
- c++(1)
- C-1
- C-1
- 【Deep C (and C++)】深入理解C/C++(1)
- 【Deep C (and C++)】深入理解C/C++(1)
- 【Deep C (and C++)】深入理解C/C++(1)
- poi导出excel
- datatables 获取某一行的json数据
- 347. Top K Frequent Elements
- Java基础知识_毕向东_Java基础视频教程笔记(14-18集合框架)
- powershell 自动编译发布
- C-1
- 001_a标签用法全解析
- OpenCV库文件介绍
- Faste RCNN 详解
- MVP模式在Android项目中的使用
- HDU 4336 Card Collector (概率-期望DP)【模板】
- c#集合类的线程安全
- @Transactional 用法
- 对IT行业大数据发展的一种目前认识