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

改了还是过不了

Posted by 36211316 at 2007-03-01 15:03:37 on Problem 1185
In Reply To:总是过不了呀 Posted by:36211316 at 2007-03-01 14:20:41
#include<stdio.h>
#include<stdlib.h>

int m,n,step;
char *str;
int place(int x,int y){
	int i;
	if(str[x*n+y]!='P')
		return 0;
	for(i=x;i>=0&&i>x-3;--i)
		if(str[i*n+y]=='T')
			return 0;
	for(i=y;i>=0&&i>y-3;--i)
		if(str[x*n+i]=='T')
			return 0;
	for(i=x;i<m&&i<x+3;++i)
		if(str[i*n+y]=='T')
			return 0;
	for(i=y;i<n&&i<y+3;++i)
		if(str[x*n+i]=='T')
			return 0;
	return 1;

}
int search(int t){
     int i,j;
     
     if(t==step)
         return 1;
     else{
		 for(i=0;i<m;++i){
            for(j=0;j<n;++j){
				if(place(i,j)){
                    str[i*n+j]='T';
					if(search(t+1)==1){
						return 1; 
					}else{
						str[i*n+j]='P';
					}
				}
			}
		 }
	 }
	 return 0;
}

int main(){
     int i=0,j;
     char c;
      
     scanf("%d %d",&m,&n);
     fflush(stdin);
     str=(char *)malloc(m*n*sizeof(char));
     while(i<m*n&&(c=getchar())!=EOF){
		 if(c!=' '&&c!='\n')
			 str[i++]=c;
	 }
     for(i=0;i<m;++i){
         for(j=0;j<n;++j)
             if(str[i*n+j]=='P')
                 ++step;
     }
     for(;step>0;--step){
		 if(search(0)){
             printf("%d",step);
			 break;
		 }
	 }
     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