poj 2482 java
来源:互联网 发布:linux 调用.so 参数 编辑:程序博客网 时间:2024/05/01 08:10
import java.util.*;public class POJ_2482 {static long height[];static long tree[];static XY p[];static TreeSet<Long> ts;static Iterator<Long> iterator;static int m;static long sum[];static long maxSum[];public static void main(String[] args)throws Exception {Scanner scan = new Scanner(System.in);while(scan.hasNext()){int n = scan.nextInt();int W = scan.nextInt();int H = scan.nextInt();height = new long[2*n];ts = new TreeSet<Long>();p = new XY[n<<1];for(int i=0;i<n;i++){p[i] = new XY(scan.nextLong(),scan.nextLong(),scan.nextLong());p[i+n] = new XY(p[i].x+W,p[i].y,-p[i].c); //x扫描线 当遇到 p[i].x+W 表示 以p[i].x为左下角的矩形已搜索结束ts.add(p[i].y); // 所以是 -p[i].c 这样刚好可以中和 成0 表示没有加上它ts.add(p[i].y+H);}m = ts.size();iterator = ts.iterator();tree = new long[m<<1];sum = new long[(m<<1)+2];maxSum = new long[(m<<1)+2];createLineTree(1);java.util.Arrays.sort(p);n *= 2;long ans = 0;for(int i=0;i<n;i++){ //原理同 x扫描线 相似insert(p[i].y,p[i].c);insert(p[i].y+H,-p[i].c);ans = Math.max(ans, maxSum[1]);}System.out.println(ans);}}private static void insert(long y, long c) {int p = 1;while(tree[p]!=y){ // 搜索要修改的点if(y<tree[p])p <<= 1;elsep = (p<<1)+1;}while(p!=0){ //更新 前面找到的修改点以及 它所有祖先点sum[p] += c;long t1 = maxSum[2*p]; // 每个根结点 是 左右子树 一起更新的结果long t2 = sum[p]-sum[2*p+1]+maxSum[2*p+1]; // 因为此树是有序的 所以每一棵子树 代表一个范围 (左根右) maxSum[p] = Math.max(t1, t2); // 而这个范围的maxSum 值 就放在根中 根中的sum值 是其所有子树的总和p /= 2;}}public static void createLineTree(int p) {if(2*p<=m) // 建立二叉 排序树 createLineTree(2*p);tree[p] = iterator.next();if(2*p+1<=m)createLineTree(2*p+1);}}class XY implements Comparable<XY>{long x;long y;long c;public XY(long x, long y, long c) {super();this.x = x;this.y = y;this.c = c;}public int compareTo(XY e) {if(this.x<e.x)return -1;else if(this.x>e.x)return 1;else{if(this.c<e.c)return -1;else if(this.c>e.c)return 1;return 0;}}}
- poj 2482 java
- POJ 2418 Java
- POJ 2299 Java
- POJ 1011 - Java
- poj 1032 java版本
- poj 2389 Java
- poj 1002 Java
- poj 1003 Java
- poj 1004 Java
- poj 1005 Java
- poj 1007 Java
- poj 1008 Java
- poj 3274 java
- poj 2706 java
- poj 3308 java
- poj 2195 java
- poj 2528 java
- poj 1703 java
- 通过函数参数获取新创建指针的三种方法
- java函数参数中:用参数值带回结果(类似传址)
- 多进程、多线程、多任务(windows vs linux)
- 优秀网游的几点要素
- IP数据报的分片与重组分析
- poj 2482 java
- 域管理环境中进行软件的推送安装
- 天天记录 - Android AsyncTask 缺陷
- 离散数学中文—外文名词对照表
- ACRush 楼天成回忆录
- 域环境下的软件发布和指派
- js的打字游戏的例子
- POJ 1305 勾股数组
- mount iso文件