在执行了用java编写的程序之后,我看到了以下输出:
java结果: 2147483647
这个数字到底是什么意思?这是密码。Tt实际上应该在ACM问题解决方案上运行随机测试用例!没办法正常停下来!当我手动停止它时,我看到这个输出:
Java结果: 2147483647
成功构建(总时间:8分49秒)
我只想知道那个数字是什么意思?
package acm;
import java.util.Random;
import java.util.Scanner;
import java.util.Vector;
public class mamoth {
static Scanner input = new Scanner(System.in);
public static String planets;
public static int H;
public static int A;
public static Random random = new Random();
public static void main(String []args)
{
while(!(planets = /*input.nextLine()*/Integer.toString(random.nextInt(10)+1) + " " + Integer.toString(random.nextInt(10)+1)).equals("0 0")){
System.out.println(planets);
//while(!(planets = input.nextLine()).equals("0 0")){
int index;
index = planets.indexOf(' ');
H = Integer.valueOf(planets.substring(0, index));
A = Integer.valueOf(planets.substring(index+1));
Vector<Integer> humanPlanets = new Vector<Integer>();
String temp = "1 0";
for(int i=0;i<H-1;i++){
temp += " 1 0";
}
planets = /*input.nextLine()*/temp;
System.out.println(planets);
//planets = input.nextLine();
int index1 = 0;
int index2;
while((index2 = planets.indexOf(' ',index1))!=-1){
humanPlanets.addElement(Integer.valueOf(planets.substring(index1, index2)));
index1= index2+1;
}
humanPlanets.addElement(Integer.valueOf(planets.substring(index1)));
Vector<Integer> aliasPlanets = new Vector<Integer>();
temp = "0 0";
for(int i=0;i<A-1;i++){
temp += " 0 0";
}
planets = /*input.nextLine()*/temp;
System.out.println(planets);
//planets = input.nextLine();
index1 = 0;
while((index2 = planets.indexOf(' ',index1))!=-1){
aliasPlanets.addElement(Integer.valueOf(planets.substring(index1, index2)));
index1= index2+1;
}
aliasPlanets.addElement(Integer.valueOf(planets.substring(index1)));
int[][] distance = new int[H][A];
for(int i=0;i<H;i++){
temp = Integer.toString(random.nextInt(100)+1);
for(int b=0;b<A-1;b++){
temp += " " + Integer.toString(random.nextInt(100)+1);
}
planets = /*input.nextLine()*//*Integer.toString(random.nextInt(100)+1) + " " + Integer.toString(random.nextInt(100)+1) + " " + Integer.toString(random.nextInt(100)+1)*/temp;
//planets = input.nextLine();
index1 = 0;
int j =0;
while((index2 = planets.indexOf(' ',index1))!=-1){
distance[i][j] = Integer.valueOf(planets.substring(index1, index2));
index1= index2+1;
j++;
}
distance[i][j] = Integer.valueOf(planets.substring(index1));
}
if(H>=A){
int[][] minimumYearsToDefeat = new int[H][A];
for(int i=0;i<H;i++){
for(int j=0;j<A;j++){
double x,y,z;
y = aliasPlanets.elementAt(j*2) + humanPlanets.elementAt(i*2+1)*distance[i][j]-humanPlanets.elementAt(i*2);
z = humanPlanets.elementAt(i*2+1) - aliasPlanets.elementAt(j*2+1);
if(z==0){
if(y<=0)
x = distance[i][j];
else
x = Integer.MAX_VALUE;
}
else{
x = y/z;
}
if(x==0){
x=1;
}
else if(x<0){
x= Integer.MAX_VALUE;
}
minimumYearsToDefeat[i][j] = (int)Math.ceil(x);
}
}
for(int i=0;i<H;i++){
for(int j=0;j<A;j++)
System.out.print(minimumYearsToDefeat[i][j]+" ");
System.out.println();
}
int[] mins = new int[A];//meqdar dehi ba big integer
for(int i=0;i<A;i++){
mins[i] = Integer.MAX_VALUE;
}
int[] minsWith = new int[A];//meqdar dehi ba -1
for(int i=0;i<A;i++){
minsWith[i] = -1;
}
for(int i=0;i<A;i++){
for(int j=0;j<H;j++){
if(minimumYearsToDefeat[j][i]<mins[i]){
mins[i] = minimumYearsToDefeat[j][i];
minsWith[i] = j;
}
}
for(int p=0;p<A;p++){
if(minsWith[i]==minsWith[p]&&p!=i&&mins[i]!=Integer.MAX_VALUE){
correctingConflict(minimumYearsToDefeat, mins, minsWith, i, p, new Vector<Integer>());
}
}
}
int result = 0;
for(int i=0;i<A;i++){
if (mins[i]>result)
result = mins[i];
}
if(result==Integer.MAX_VALUE){
System.out.println("IMPOSSIBLE");
}
else{
System.out.println(result);
}
}
else{
System.out.println("IMPOSSIBLE");
}
}
}
public static void correctingConflict(int[][] W, int[] mins, int[] minsWith, int i, int p, Vector<Integer> vector){
/*for(int v=0;v<A;v++){
System.out.print(minsWith[v]+" ");
}
System.out.println();
for(int v=0;v<vector.size();v++){
System.out.print(vector.elementAt(v)+" ");
}
System.out.println();*/
int nextMin1 = Integer.MAX_VALUE;
int nextMin2 = Integer.MAX_VALUE;
int nextMinWith1 = minsWith[i];
int nextMinWith2 = minsWith[p];
for(int q=0;q<H;q++){
if(W[q][i]<nextMin1 && W[q][i]>=mins[i] && q!=minsWith[i] && !vector.contains(q)){
nextMin1 = W[q][i];
nextMinWith1 = q;
}
}
for(int q=0;q<H;q++){
if(W[q][p]<nextMin2 && W[q][p]>=mins[p] && q!=minsWith[p] && !vector.contains(q)){
nextMin2 = W[q][p];
nextMinWith2 = q;
}
}
if(nextMin1<=nextMin2){
if (nextMin1==mins[i]) {
vector.addElement(minsWith[p]);
} else {
vector.removeAllElements();
}
mins[i] = nextMin1;
minsWith[i] = nextMinWith1;
//conflict checking
for(int s=0;s<A;s++){
if(minsWith[i]==minsWith[s]&&s!=i&&mins[i]!=Integer.MAX_VALUE){
correctingConflict(W, mins, minsWith, i, s, vector);
return;
}
}
}
else if(nextMin2<nextMin1){
if (nextMin2==mins[p]) {
vector.removeAllElements();
vector.addElement(minsWith[p]);
} else {
vector.removeAllElements();
}
mins[p] = nextMin2;
minsWith[p] = nextMinWith2;
//conflict checking
for(int s=0;s<A;s++){
if(minsWith[p]==minsWith[s]&&s!=p&&mins[p]!=Integer.MAX_VALUE){
correctingConflict(W, mins, minsWith, p, s, vector);
return;
}
}
}
}
}发布于 2010-07-03 08:02:32
嗯,你还没有展示你是如何执行你的程序的,或者你的程序是做什么的。我猜想它可能是进程的退出代码,尽管通常如果没有任何错误,退出代码是0。
如果你想得到更好的答案,请在问题中提供更多的信息。
发布于 2010-07-03 09:57:30
您可以在代码中的五个不同位置分配Integer.MAX_VALUE;其中一个位置是mins数组中的元素。
在main()方法末尾附近的代码可以从mins数组中打印出值:
int result = 0; for(int i=0;i<A;i++){ if (mins[i]>result) result = mins[i]; } if(result==Integer.MAX\_VALUE){ System.out.println("IMPOSSIBLE"); } else{ System.out.println(result); } } else{ System.out.println("IMPOSSIBLE"); }
下面是一个小测试程序,以了解Integer.MAX_VALUE实际上是什么:
$ cat test.java ; javac test.java ; java sars
class sars {
public static void main(String args[]) {
System.out.println("Integer.MAX_VALUE: " + Integer.MAX_VALUE);
}
}
Integer.MAX_VALUE: 2147483647我之前关于a -1泄露到某个地方的评论是错误的--您已经在代码中嵌入了五次有趣的值。)我不知道哪一个在泄漏,或者你的算法是否真的像它应该的那样工作。祝你好运:)但至少在你的完整代码发布后,可能有人会帮你找到我们都缺少的东西。
发布于 2010-07-03 16:35:15
如果您有一个默认的NetBeans项目,并且您要从NetBeans启动它,那么它将由Ant使用项目目录中生成的构建脚本启动。要缩小问题的范围,请尝试从命令行自己启动程序:
java acm.mamothhttps://stackoverflow.com/questions/3170762
复制相似问题