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

水题啊大水题,忘了include string导致CE一次,真是没SEI了。

Posted by KatrineYang at 2016-07-11 21:20:54 on Problem 1111
#include <iostream>
#include <string>
using namespace std;

int hang, lie;

bool state[32][32];

bool zhany[32][32];

int zc = 0;

void init(){
	zc = 0;
	for(int i = 0; i < hang; i++){
		for(int j = 0; j < lie; j++){
			zhany[i][j] = 0;
		}
	}
}

int zcgx(int ch, int cl){
	int res = 0;
	if(cl == 0 || !state[ch][cl-1]) res++;
	if(cl == lie-1 || !state[ch][cl+1]) res++;
	if(ch == 0 || !state[ch-1][cl]) res++;
	if(ch == hang-1 || !state[ch+1][cl]) res++;
	return res;
}

void jisuan(int ch, int cl){
	zc += zcgx(ch, cl);
	zhany[ch][cl] = true;
	if(ch>0 && !zhany[ch-1][cl] && state[ch-1][cl]) jisuan(ch-1, cl);
	if(ch < hang-1 && !zhany[ch+1][cl] && state[ch+1][cl]) jisuan(ch+1, cl);
	if(cl>0 && !zhany[ch][cl-1] && state[ch][cl-1]) jisuan(ch, cl-1);
	if(cl < lie-1 && !zhany[ch][cl+1] && state[ch][cl+1]) jisuan(ch, cl+1);
	if(ch>0 && cl>0 && !zhany[ch-1][cl-1] && state[ch-1][cl-1]) jisuan(ch-1, cl-1);
	if(ch>0 && cl<lie-1 && !zhany[ch-1][cl+1] && state[ch-1][cl+1]) jisuan(ch-1, cl+1);
	if(ch<hang-1 && cl>0 && !zhany[ch+1][cl-1] && state[ch+1][cl-1]) jisuan(ch+1, cl-1);
	if(ch<hang-1 && cl<lie-1 && !zhany[ch+1][cl+1] && state[ch+1][cl+1]) jisuan(ch+1, cl+1);
}

int main() {
	while(1){
		int chang, clie;
		cin >> hang >> lie >> chang >> clie;
		if(hang == 0) return 0;
		for(int i = 0; i < hang; i++){
			string s;
			cin >> s;
			for(int j = 0; j < lie; j++){
				if(s[j] == '.') state[i][j] = 0;
				else state[i][j] = 1;
			}
		}
		init();
		jisuan(chang-1, clie-1);
		cout << zc << endl;
	}
	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