poj 3045 Cow Acrobats
来源:互联网 发布:哪些女装淘宝店铺推荐 编辑:程序博客网 时间:2024/05/30 02:23
按照w+s排序然后计算
这个题目和动态规划中的叠乌龟一脉相承。
还有动态规划里的stacking box和stacking turtle是有很大区别的
这个证明其实蛮复杂的,回头写一下
想了好久,决定瞎逼把DP里叠乌龟的sorting方法用一下,居然过了,看来多刷题还是有用。
我不会证明但是我会A。。。
/*ID: daniel.20LANG: JAVATASK: fence8*/import java.io.*;import java.math.BigInteger;import java.util.*;class cow implements Comparable<cow>{ int w,s; public cow(int a,int b){ w=a;s=b; } @Override public int compareTo(cow t) { return (this.w+this.s)-(t.w+t.s); }}class problem{ int n; cow[] arr; void solver() throws IOException{ long start = System.currentTimeMillis(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); n = Integer.valueOf(reader.readLine()); arr = new cow[n]; for(int i=0;i<n;i++){ StringTokenizer st = new StringTokenizer(reader.readLine()); int t1 = Integer.valueOf(st.nextToken()); int t2 = Integer.valueOf(st.nextToken()); arr[i]=new cow(t1,t2); } Arrays.sort(arr); long sum[] = new long[n]; sum[0] = arr[0].w; long max = -arr[0].s; for(int i=1;i<n;i++){ sum[i]=sum[i-1]+arr[i].w; if(sum[i-1]-arr[i].s>max)max=sum[i-1]-arr[i].s; } //Dumper.print_1_arr(sum, n); System.out.println(max); } }public class fence8 { public static void main (String [] args) throws Exception { problem p = new problem(); p.solver(); }}
0 0
- poj-3045 Cow Acrobats
- POJ 3045 Cow Acrobats
- POJ 3045-Cow Acrobats
- POJ-3045-Cow Acrobats
- POJ 3045 Cow Acrobats
- poj 3045 Cow Acrobats
- POJ 3045 Cow Acrobats
- poj 3045 Cow Acrobats
- POJ-3045Cow Acrobats
- poj 3045 Cow Acrobats
- Cow Acrobats - POJ 3045 排序
- POJ 3045 Cow Acrobats 贪心
- poj 3045 Cow Acrobats(数学题)
- poj 3045 Cow Acrobats 贪心
- POJ 3045 - Cow Acrobats(贪心)
- POJ - 3045 Cow Acrobats 贪心
- poj 3045 Cow Acrobats 贪心
- poj 3045 Cow Acrobats 【二分】
- 运行tomcat7w.exe,提示:指定的服务未安装
- hdoj 1248 完全背包问题
- 黑马程序员——正则表达式
- 注册表中关闭组策略
- ios即时通讯客户端开发之-mac上安装MySQL
- poj 3045 Cow Acrobats
- Android系统回顾(二):Android基础知识
- iOS shareSDK 实现第三方登陆参考资料
- acer(宏基) Aspire E1-472G ubuntu-12.04下安装无线网卡驱动
- XMPP聊天之Openfire 的安装和配置---Mac OS
- 如何实现一个可靠的IM即时通讯应用
- 【spring】缓存超时设置
- java 编译
- c语言排序问题