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

高手帮忙给看看,为什么老是WA,答案正确呀,谢谢谢谢!!!

Posted by zhb_msqx at 2007-08-25 23:37:55 on Problem 1128
//思路就是线对输入进行处理,记录每个字母的左上边坐标和右下边坐标,每次判断如果成立就把这个字母原来位置改成'.'继续判断,判断的时候把'.'看做和当前字母一样。

#include <iostream>
#include <fstream>
using namespace std;


int m,n;
char c[35][35];
struct cp{
	char str;
	int leftx,lefty;
	int rightx,righty;
} ch[100];
int chnum;

char sol[50];
int solnum;

int mark[50];


bool check(int p){
	char curc=ch[p].str;
	int lx=ch[p].leftx;
	int ly=ch[p].lefty;
	int rx=ch[p].rightx;
	int ry=ch[p].righty;
	for(int i=lx;i<=rx;i++){
		if(c[i][ly]!=curc&&c[i][ly]!='.')return false;
		if(c[i][ry]!=curc&&c[i][ry]!='.')return false;
	}
	for(i=ly;i<=ry;i++){
		if(c[lx][i]!=curc&&c[lx][i]!='.')return false;
		if(c[rx][i]!=curc&&c[rx][i]!='.')return false;
	}
	for(i=lx;i<=rx;i++){
		c[i][ly]='.';
		c[i][ry]='.';
	}
	for(i=ly;i<=ry;i++){
		c[lx][i]='.';
		c[rx][i]='.';
	}
	//	cout<<"YES"<<endl;
	return true;
}




void func(char cc,int x,int y){
	for(int i=0;i<chnum;i++){
		if(ch[i].str==cc)break;
	}
	if(i==chnum){
		ch[chnum].str=cc;
		ch[chnum].leftx=x;
		ch[chnum].rightx=x;
		ch[chnum].lefty=y;
		ch[chnum].righty=y;
		chnum++;
	}else{
		if(x<=ch[i].leftx&&y<=ch[i].lefty){
			ch[i].leftx=x;ch[i].lefty=y;
		}
		
		if(x>=ch[i].rightx&&y>=ch[i].righty){
			ch[i].rightx=x;ch[i].righty=y;
		}
	}
	
}
void init(){
	chnum=0;
	solnum=0;
	memset(mark,0,sizeof(mark));
	for(int i=0;i<100;i++){
		ch[i].leftx=10000;
		ch[i].lefty=10000;
		ch[i].rightx=-1;
		ch[i].righty=-1;
	}
	
}
/*
void print(){
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cout<<c[i][j];
}
cout<<endl;
}

  
	
	  }
*/
void main(){
		ifstream cin("data.txt");
	while(cin>>m>>n){
		init();
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				cin>>c[i][j];
				if(c[i][j]!='.'){
					func(c[i][j],i,j);
				}
			}
		}
		/*	for(i=0;i<chnum;i++){
		cout<<ch[i].str<<" "<<ch[i].leftx<<" "<<ch[i].lefty<<" "<<ch[i].rightx<<" "<<ch[i].righty<<endl;
	}*/
		i=0;
		while(i<chnum){
			for(int k=0;k<chnum;k++){
				if(mark[k]==0){
					if(check(k)){
						mark[k]=1;
						sol[i++]=ch[k].str;
						//	print();
						//	cout<<endl;
					}
				}
			}
		}
		for(i=chnum-1;i>=0;i--){
			cout<<sol[i];
		}
		cout<<endl;
	}
	
	
}

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