[ create a new paste ] login | about

Link: http://codepad.org/4lqUZcoc    [ raw code | output | fork ]

hoaithu.melody - C++, pasted on Jun 19:
//Bao ve nong trai

import java.util.Scanner;


public class Solution {
static int A[][];
static int dx[]={-1,0,1,-1,1,-1,0,1};
static int dy[]={-1,-1,-1,0,0,1,1,1};
static int kiux[]=new int [10000000];
static int kiuy[]=new int [1000000];
static int l,r;
static boolean danhdau[][];
	public static void main(String[] args) {
	//System.setIn(new FileInputStream("baovenongtrang.txt"));
	Scanner sc=new Scanner(System.in);
	int T=sc.nextInt();
	for (int t = 1; t <=T; t++) {
		int n=sc.nextInt();
		int m=sc.nextInt();
		A=new int [n][m];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A[0].length; j++) {
				A[i][j]=sc.nextInt();
			}
		}
		danhdau=new boolean[n][m];
		int dinh=0;
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A[0].length; j++) {
				if(!danhdau[i][j]){
				if(check(i,j)) dinh++;
				}
			}
		}
		System.out.println("#"+t+" "+dinh);
			}
		}
	static boolean check(int x,int y){
		int kt=0;
		l=-1;r=-1;
		push(x,y);
		co:while(l!=r){
			pop();
			int xa=kiux[l];
			int ya=kiuy[l];
		for (int i = 0; i <8; i++) {
			int x1=xa+dx[i];
			int y1=ya+dy[i];
			if(x1>=0&&y1>=0&&x1<A.length&&y1<A[0].length){
				if(A[x1][y1]>A[x][y]){
					kt=1;
				}
				if(A[x1][y1]==A[xa][ya]&&!danhdau[x1][y1]){
					push(x1,y1);
				}
			}
		}
		}
		if(kt==1) return false;
		return true;
	}
	static void push(int x,int y){
		kiux[++r]=x;
		kiuy[r]=y;
		danhdau[x][y]=true;
	}
	static void pop(){
		l++;
	}
}


Output:
1
2
Line 3: error: 'import' does not name a type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: