(ACM)ZOJ Problem Set - 2922
提交结果为:Wrong Answer 。为什么是错误答案?? 下面是我的代码
import java.util.*;
import java.io.*;
public class Main {
int [][]a;
public void deal(){
Scanner in=new Scanner(new BufferedInputStream(System.in));
while(in.hasNext())
{
int n=in.nextInt();
int m=in.nextInt();
int sum=0;
a=new int[n+1][m+1];
for(int x=1;x<=n;x++)
{
for(int y=1;y<=m;y++)
{
a[x][y]=in.nextInt();
}
}
for(int x=n;x>0;x--)
{
for(int y=m;y>0;y--)
{
if(a[x][y]!=0)
{
int pow=a[x][y];
a[x][y]=0;
Bombs(x,y,pow);
sum++;
}
}
}
System.out.println(sum);
}
}
private void Bombs(int n,int m,int pow)
{
for(int x=n;x>0;x--)
{
if(a[x][m]!=0)
{
pow=a[x][m];
a[x][m]=0;
Bombs(x,m,pow);
}
}
int stop=pow;
for(int y=m-1;y>0;y--)
{
if(a[n][y]!=0)
{
pow=a[n][y];
a[n][y]=0;
Bombs(n,y,pow);
}
stop--;
if(stop==0)
{
break;
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Main myClass=new Main();
myClass.deal();
}
}