Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
改了还是过不了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator