poj 1009 java_(需要大神,请求解决,遇见runtime error 错误)poj 1009 java

本地测试 ,没有错误,提交后 runtime error

5acd67fb32fdfd4d2c16262fa3040eb1.pngDescriptionIONU Satellite Imaging, Inc. records and stores very large images using run length encoding. You are to write a program that reads a compressed image, finds the edges in the image, as described below, and outputs another compressed image of the detected edges. A simple edge detection algorithm sets an output pixel's value to be the maximum absolute value of the differences between it and all its surrounding pixels in the input image. Consider the input image below: The upper left pixel in the output image is the maximum of the values |2021年02月16日|,|2021年02月16日0|, and |2021年02月16日0|, which is 85. The pixel in the 4th row, 2nd column is computed as the maximum of |12021年02月16日0|, |12021年02月16日0|, |12021年02月16日0|, |12021年02月16日5|, |12021年02月16日|, |12021年02月16日5|,|12021年02月16日5|, and |12021年02月16日|, which is 150. Images contain 2 to 1,000,000,000 (109) pixels. All images are encoded using run length encoding (RLE). This is a sequence of pairs, containing pixel value (2021年02月16日5) and run length (2021年02月16日9). Input images have at most 1,000 of these pairs. Successive pairs have different pixel values. All lines in an image contain the same number of pixels. InputInput consists of information for one or more images. Each image starts with the width, in pixels, of each image line. This is followed by the RLE pairs, one pair per line. A line with 0 0 indicates the end of the data for that image. An image width of 0 indicates there are no more images to process. The first image in the example input encodes the 5x7 input image above. OutputOutput is a series of edge-detected images, in the same format as the input images, except that there may be more than 1,000 RLE pairs. Sample Input715 4100 1525 2175 225 5175 225 50 01035 500000000200 5000000000 03255 110 1255 210 1255 210 1255 10 00Sample Output785 50 285 575 10150 275 30 2150 20 40 0100 499999990165 200 4999999900 03245 90 00HintA brute force solution that attempts to compute an output value for every individual pixel will likely fail due to space or time constraints.

import java.math.BigDecimal; import java.nio.Buffer;import java.util.ArrayList;import java.util.List; import java.util.Scanner; import java.util.Set;import java.util.TreeSet;import org.omg.CORBA.DATA_CONVERSION;/** * * @author baoyou E-mail:curiousby@163.com * @version 创建时间:2021年02月16日2021年02月16日 下午11:43:37 * des: */public class BaoyPoj1009Test2 {public static void main(String[] args) {Scanner in = new Scanner(System.in);for (;;) {int cols = in.nextInt();BigDecimal num = new BigDecimal(0);System.out.println(cols);List target = new ArrayList();for (;;) {int a = in.nextInt();BigDecimal b = in.nextBigDecimal();num = num.add(b);if (a != 0 && b.intValue() != 0)target.add(new Node(a, target.size() == 0 ? b : b.add(target.get(target.size() - 1).num)));if (a == 0 && b.intValue() == 0) {BigDecimal rows = num.divide(new BigDecimal(cols),BigDecimal.ROUND_DOWN);Set source = new TreeSet();BigDecimal current = new BigDecimal(1);find9(cols, rows, current, target , source);for (int i = 0; i < target.size()-1; i++) { Node node = target.get(i); current = new BigDecimal(1).add(node.num); find9(cols, rows, current, target , source); } boolean first =true;int absResult=0;BigDecimal numTemp= new BigDecimal(0);BigDecimal numResult= new BigDecimal(0);for ( DataNode dnode:source) {if (first) {absResult = dnode.abs;numResult = dnode.start;first = false;}else{if (absResult == dnode.abs) {//numResult = dnode.start;}else{System.out.println(absResult + " " + dnode.start.subtract(numResult));absResult = dnode.abs;numResult = dnode.start;}}}System.out.println(absResult + " " + num.subtract(numResult).add(new BigDecimal(1)));System.out.printf("%d %d

", 0, 0);break;}}if (cols == 0) {System.out.println(0);break;}}}public static void find9(int cols, BigDecimal rows, BigDecimal i, List target ,Set source){ BigDecimal start = new BigDecimal(0); int abs = 0; //self start = i; if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows, start, target);source.add(new DataNode(start,abs));} // 上 (x,y-1)if (i.compareTo(new BigDecimal(cols)) > 0) { start = i.subtract(new BigDecimal(cols));if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows, start, target);source.add(new DataNode(start,abs));}}// 下 (x,y+1)if (i.compareTo(rows.subtract(new BigDecimal(1)).multiply( new BigDecimal(cols))) <= 0) {start = i.add(new BigDecimal(cols));if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows, start, target);source.add(new DataNode(start,abs));}}// 左 (x-1,y)if (i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(1)) != 0) {start = i.subtract(new BigDecimal(1));if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows,start, target);source.add(new DataNode(start,abs));}}// 右(x+1,y)if (i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(0)) != 0) { start = i.add(new BigDecimal(1)); if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows, start, target);source.add(new DataNode(start,abs));}}// 左上 (x-1,y-1)if (i.compareTo(new BigDecimal(cols)) > 0 && i.remainder(new BigDecimal(cols)).compareTo( new BigDecimal(1)) != 0) {start = i.subtract(new BigDecimal(cols)).subtract( new BigDecimal(1));if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows, start, target);source.add(new DataNode(start,abs));}}// 右上 (x+1,y-1)if (i.compareTo(new BigDecimal(cols)) > 0 && i.remainder(new BigDecimal(cols)).compareTo( new BigDecimal(0)) != 0) {start = i.subtract(new BigDecimal(cols)).add(new BigDecimal(1));if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows, start, target);source.add(new DataNode(start,abs));}}// 左下 (x-1,y+1)if (i.compareTo(rows.subtract(new BigDecimal(1)).multiply( new BigDecimal(cols))) <= 0 && i.remainder(new BigDecimal(cols)).compareTo( new BigDecimal(1)) != 0) {start = i.add(new BigDecimal(cols)).subtract(new BigDecimal(1));if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows, start, target);source.add(new DataNode(start,abs));}}// 右下 (x+1,y+1)if (i.compareTo(rows.subtract(new BigDecimal(1)).multiply(new BigDecimal(cols))) <= 0 && i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(0)) != 0) {start = i.add(new BigDecimal(cols)).add(new BigDecimal(1));if (!source.contains(new DataNode(start))) {abs = maxABS(cols, rows, start, target);source.add(new DataNode(start,abs));}}}public static int maxABS(int cols, BigDecimal rows, BigDecimal i, List target) {int max = 0;int current = getValue(i, target);BigDecimal location = new BigDecimal(0);// 上 (x,y-1)if (i.compareTo(new BigDecimal(cols)) <= 0) {int a = 0;if (a > max)max = a;} else {location = i.subtract(new BigDecimal(cols));int a = Math.abs(getValue(location, target) - current);if (a > max)max = a;}// 下 (x,y+1)if (i.compareTo(rows.subtract(new BigDecimal(1)).multiply(new BigDecimal(cols))) > 0) {int a = 0;if (a > max)max = a;} else {location = i.add(new BigDecimal(cols));int a = Math.abs(getValue(location, target) - current);if (a > max)max = a;}// 左 (x-1,y)if (i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(1)) == 0) {int a = 0;if (a > max)max = a;} else {location = i.subtract(new BigDecimal(1));int a = Math.abs(getValue(location, target) - current);if (a > max)max = a;}// 右(x+1,y)if (i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(0)) == 0) {int a = 0;if (a > max)max = a;} else {location = i.add(new BigDecimal(1));int a = Math.abs(getValue(location, target) - current);if (a > max)max = a;}// 左上 (x-1,y-1)if (i.compareTo(new BigDecimal(cols)) <= 0) {int a = 0;if (a > max)max = a;} else if (i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(1)) == 0) {int a = 0;if (a > max)max = a;} else {location = i.subtract(new BigDecimal(cols)).subtract(new BigDecimal(1));int a = Math.abs(getValue(location, target) - current);if (a > max)max = a;}// 右上 (x+1,y-1)if (i.compareTo(new BigDecimal(cols)) <= 0) {int a = 0;if (a > max)max = a;} else if (i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(0)) == 0) {int a = 0;if (a > max)max = a;} else {location = i.subtract(new BigDecimal(cols)).add(new BigDecimal(1));int a = Math.abs(getValue(location, target) - current);if (a > max)max = a;}// 左下 (x-1,y+1)if (i.compareTo(rows.subtract(new BigDecimal(1)).multiply(new BigDecimal(cols))) > 0) {int a = 0;if (a > max)max = a;} else if (i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(1)) == 0) {int a = 0;if (a > max)max = a;} else {location = i.add(new BigDecimal(cols)).subtract(new BigDecimal(1));int a = Math.abs(getValue(location, target) - current);if (a > max)max = a;}// 右下 (x+1,y+1)if (i.compareTo(rows.subtract(new BigDecimal(1)).multiply(new BigDecimal(cols))) > 0) {int a = 0;if (a > max)max = a;} else if (i.remainder(new BigDecimal(cols)).compareTo(new BigDecimal(0)) == 0) {int a = 0;if (a > max)max = a;} else {location = i.add(new BigDecimal(cols)).add(new BigDecimal(1));int a = Math.abs(getValue(location, target) - current);if (a > max)max = a;}return max;}public static int getValue(BigDecimal location, List target) {for (Node d : target) {if (d.num.compareTo(location) >= 0)return d.ascii;}return 0;}static class Node {public int ascii;public BigDecimal num;public Node(int ascii, BigDecimal num) {this.ascii = ascii;this.num = num;}@Overridepublic String toString() { StringBuffer sb= new StringBuffer();sb.append("{").append("ascii:"+ascii).append(",num:"+num).append("}"); return sb.toString();}}static class DataNode implements Comparable{public BigDecimal start;public int abs;public DataNode(BigDecimal start){this.start = start;}public DataNode(BigDecimal start, int abs) { this.start = start;this.abs = abs;} @Overridepublic boolean equals(Object obj) { if (obj instanceof DataNode) if (((DataNode) obj).start == this.start) return true; return false;}public int compareTo(Object o) {if (o instanceof DataNode){ if (((DataNode) o).start .compareTo(this.start) == 0) return 0; else if(((DataNode) o).start .compareTo(this.start) < 0) return 1; else return -1;}elsereturn -1;} @Overridepublic String toString() { StringBuffer sb= new StringBuffer();sb.append("{").append("start:"+start).append(",abs:"+abs).append("}"); return sb.toString();}}}

测试没有问题 ,可是 出现了 runtime error 百度了 好多人的 ,似乎 也有 这个 问题 ,就是没有给出跟多的提示

知道答案及错误原因请留言,谢谢

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。

谢谢您的赞助,我会做的更好!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值