Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

H2O

Posted by KatrineYang at 2016-11-14 12:23:57 on Problem 1548
#include <stdio.h>

int has[30][30];
int mxx,mxy,cnt;
int solve(){
	int res = 0;
	while(cnt>0){
		int pos = 1;
		for(int i = 1; i <= mxx; i++){
			int mxPos = 0;
			for(int j = mxy; j >= pos; j--){
				if(has[i][j]){
					mxPos = j;
					break;
				}
			}
			if(mxPos == 0) continue;
			for(int j = pos; j <= mxPos; j++){
				if(has[i][j]){
					has[i][j] = 0;
					cnt--;
				}
			}
			pos = mxPos;
		}
		res++;
	}
	return res;
}

int main(int argc, char **argv){
	while(1){
		int a,b,c,d;
		mxx=0,mxy=0,cnt=0;
		scanf("%d%d",&a,&b);
		if(a==-1) break;
		for(int i = 1; i < 30; i++){
			for(int j = 1; j < 30; j++){
				has[i][j] = 0;
			}
		}
		while(1){
			scanf("%d%d",&c,&d);
			has[a][b] = 1;
			cnt++;
			if(a>mxx) mxx=a;
			if(b>mxy) mxy=b;
			if(!c) break;
			a=c; b=d;
		}
		printf("%d\n", solve());
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator