[ create a new paste ] login | about

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

yifan666 - C, pasted on Aug 10:
// tim dau biet diem cuoi(di thang)

#include <stdio.h>

int main() {
	int N, a[100][100],i,x, y, j, test_case, count, min;
	int Answer;
//	freopen("input.txt", "r", stdin);
	for(test_case=0; test_case<10; test_case++){
		Answer=0;
		scanf("%d", &N);
		
		for(i=0; i<100; i++){
			for(j=0; j<100; j++)
	 		{
	 			scanf("%d", &a[i][j]);
			 }
		}		
		min =0;
		int k=2;
		min=10000;
		for(j=0; j<100; j++){
			x=0;
			count=0;
			if(a[0][j]==1){
				//printf("%d %d \n", a[0][j],  j);
				y=j;	
				while (x<=99){
					if(y>0 && a[x][y-1]>0 && a[x][y-1]!=k){
						a[x][y]=k;
						y--;
						count++;
					}else if(y<99 && a[x][y+1]>0 && a[x][y+1]!=k ){
						a[x][y]=k;
						y++;
						count++;
					}else {
						a[x][y]=k;
						x++;
					}
				}
				k++;
				if(count<=min) {
				min=count;
				Answer = j;
				}
			}
		}
		printf("#%d ", test_case+1);
		printf("%d \n", Answer);
	}
	return 0;
}


Output:
1
Timeout


Create a new paste based on this one


Comments: