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

简介:      本地测试 ,没有错误,提交后 runtime error     Description IONU Satellite Imaging, Inc. records and stores very large images using run length encoding.

 

 

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

 

 

Description

IONU 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 |15-15|,|15-100|, and |15-100|, which is 85. The pixel in the 4th row, 2nd column is computed as the maximum of |175-100|, |175-100|, |175-100|, |175-175|, |175-25|, |175-175|,|175-175|, and |175-25|, 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 (0-255) and run length (1-109). 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. 
Input

Input 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. 
Output

Output 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 Input

7
15 4
100 15
25 2
175 2
25 5
175 2
25 5
0 0
10
35 500000000
200 500000000
0 0
3
255 1
10 1
255 2
10 1
255 2
10 1
255 1
0 0
0
Sample Output

7
85 5
0 2
85 5
75 10
150 2
75 3
0 2
150 2
0 4
0 0
10
0 499999990
165 20
0 499999990
0 0
3
245 9
0 0
0
Hint

A 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 创建时间:2015年10月3日 下午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<Node> target = new ArrayList<Node>();
			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<DataNode> source = new TreeSet<DataNode>();
					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\r\n", 0, 0);
					break;
				}
			}
			if (cols == 0) {
				System.out.println(0);
				break;
			}
		}
		
	}

	public static void  find9(int cols, BigDecimal rows, BigDecimal i, List<Node> target  ,Set<DataNode> 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<Node> 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<Node> 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;
		}
		
		@Override
		public 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;
		}
		
	   @Override
		public 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;
			}else
				return -1;
		} 
	   
		
		@Override
		public String toString() { 
			StringBuffer sb= new StringBuffer();
			sb.append("{")
			.append("start:"+start)
			.append(",abs:"+abs)
			.append("}"); 
			return sb.toString();
		}
	}

}

 

 

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

 

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

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



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

 

 

目录
相关文章
|
13天前
|
Java 开发工具 流计算
flink最新master代码编译出现Java Runtime Environment 问题
在尝试编译Flink源码时遇到Java运行时环境致命错误:EXCEPTION_ACCESS_VIOLATION。问题出现在JVM.dll+0x88212。使用的是Java 11.0.28和Java HotSpot(TM) 64-Bit Server VM。系统为Windows客户端,没有生成核心dump文件。错误日志保存在hs_err_pid39364.log和replay_pid39364.log。要解决这个问题,建议检查JDK版本兼容性,更新JDK或参照错误报告文件提交Bug至http://bugreport.java.com/bugreport/crash.jsp。
|
18天前
Error:java.util.zip.ZipException: duplicate entry: com/google/firebase/iid/zzc.class ,EvalIssueExcep
Error:java.util.zip.ZipException: duplicate entry: com/google/firebase/iid/zzc.class ,EvalIssueExcep
7 0
|
4月前
|
Kubernetes Java Linux
Linux|操作系统|Error: Could not create the Java Virtual Machine 报错的解决思路
Linux|操作系统|Error: Could not create the Java Virtual Machine 报错的解决思路
430 0
|
5天前
|
Java Maven
【Java报错】显示错误“Error:java: 程序包org.springframework.boot不存在“
【Java报错】显示错误“Error:java: 程序包org.springframework.boot不存在“
23 3
|
2月前
|
Java
IDEA Error:java: Compilation failed: internal java compiler error 解决办法
IDEA Error:java: Compilation failed: internal java compiler error 解决办法
|
20天前
|
Java Maven
运行maven项目出现Error:java: JDK isn‘t specified for module ‘XXX‘
运行maven项目出现Error:java: JDK isn‘t specified for module ‘XXX‘
11 0
|
3月前
|
Java
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
29 1
|
3月前
|
监控 应用服务中间件
idea debug模式启动Tomcat报错:Error running ‘tomcat8‘: java.net.SocketException “socket closed“
idea debug模式启动Tomcat报错:Error running ‘tomcat8‘: java.net.SocketException “socket closed“
|
4月前
|
分布式计算 Linux Spark
【已解决】Caused by: java.net.SocketException: Connection reset by peer: socket write error
【已解决】Caused by: java.net.SocketException: Connection reset by peer: socket write error
70 0
|
4月前
|
SQL 分布式计算 Hadoop
【已解决[ERROR] Could not execute SQL statement. Reason:java.lang.ClassNotFoundException: org.apache.had
【已解决[ERROR] Could not execute SQL statement. Reason:java.lang.ClassNotFoundException: org.apache.had
75 0