讨论 / 帮忙。。初学深搜。请教
轻描.L 2011-11-08 15:59:00
点我顶贴 收藏 删除
program robot;

const

dx:array[1..4]of integer=(-1,0,1,0);

dy:array[1..4]of integer=(0,1,0,-1);

var

v:array[0..51,0..51]of boolean;

vx:array[0..51,0..51]of 0..1;

sum:array[0..51,0..51]of longint;

setx:array[1..51,1..51]of 0..1;

ans:integer;

max:integer;

ch:string;

n,m,x1,y1,i,j,k,x,y:longint;

procedure dfs(x,y:longint);

Begin

for k:=1 to 4 do

begin

if (x+dx[k]<0)or(x+dx[k]>n)or(y+dy[k]<0)or(y+dy[k]>n) then exit else

if (v[x+dx[k],y+dy[k]]=true)and(vx[x+dx[k],y+dy[k]]=1) then

begin

vx[x+dx[k],y+dy[k]]:=0;

inc(sum[x+dx[k],y+dy[k]],1);

dfs(x+dx[k],y+dy[k]);

vx[x+dx[k],y+dy[k]]:=1;

end;

end;

end;

Begin

readln(n,m);

for i:=1 to m+1 do

begin

v[0,i]:=false;

v[n+1,i]:=false;

end;

for i:=0 to n+1 do

begin

v[i,0]:=false;

v[i,m+1]:=false;

end;

for i:=1 to n do

begin

readln(ch);

for j:=1 to m do

begin

if ch[j]='.' then v[i,j]:=true;

if ch[j]='#' then v[i,j]:=false;

if ch[j]='R' then begin v[i,j]:=true; setx[i,j]:=1; end;

end; end;

filldword(sum,sizeof(sum)div 4,0);

for i:=1 to n do

for j:=1 to m do

begin

if setx[i,j]=1 then begin

fillchar(vx,sizeof(vx),1);

vx[i,j]:=0;

sum[i,j]:=1;

dfs(i,j);

end;

end;

max:=0;

for i:=1 to n do

for j:=1 to m do

if sum[i,j]>max then max:=sum[i,j];

writeln(max);

end.

#1 744129844@2011-11-08 10:56:00
回复 删除
宽搜吧,同学

RT

#2 轻描.L@2011-11-08 14:19:00
回复 删除
去去去

去去去去去去

#3 zgh@2011-11-08 14:54:00
回复 删除
#include<iostream>

#include<cstring>

using namespace std;

struct node

{

int adj;

struct node *next;

};

node *g[10000];

bool visited[10000]={0};

void dfs(int x)

{

node *p;

p=new node;

cout<<x<<' ';

visited[x]=1;

p=g[x];

while(p)

{

if(!visited[p->adj])

dfs(p->adj);

p=p->next;

}

}

int main()

{

node *p;

int n,en,i,x,y;

cin>>n>>en;

memset(g,0,sizeof(g));

for(i=0;i<en;i++)

{

cin>>x>>y;

p=new node;

p->adj=y;

p->next=g[x];

g[x]=p;

p=new node;

p->adj=x;

p->next=g[y];

g[y]=p;

}

for(i=1;i<=n;i++)

if(!visited[i])

dfs(i);

cout<<endl;

system("pause");

return 0;

}

#4 不若轮回@2011-11-08 15:46:00
回复 删除
我的程序

program exam;

const

s:array [1..4,1..2] of longint=((0,1),(1,0),(-1,0),(0,-1));

var

n,m,i,j,k,tot,ans:longint;

a:array [1..50,1..50] of char;

d:array [1..2500,1..2] of longint;

procedure doit(x,y:longint);

var

i:longint;

begin

if a[x,y]='R' then inc(tot);

a[x,y]:='#';

for i:=1 to 4 do

if (x+s[i,1]>0) and (x+s[i,1]<=n) and (y+s[i,2]>0) and (y+s[i,2]<=m) and

(a[x+s[i,1],y+s[i,2]]<>'#') then doit(x+s[i,1],y+s[i,2]);

end;

begin

readln(n,m); k:=0;

for i:=1 to n do begin

for j:=1 to m do begin

read(a[i,j]);

if a[i,j]='R' then begin

inc(k); d[k,1]:=i; d[k,2]:=j;

end; end;

readln; end;

ans:=0;

for i:=1 to k do

if a[d[i,1],d[i,2]]='R' then begin

tot:=0;

doit(d[i,1],d[i,2]);

if ans<tot then ans:=tot; end;

writeln(ans);

readln;

end.

#5 轻描.L@2011-11-08 15:59:00
回复 删除
回复 地毯zgh 的帖子

不是难为我看不懂C++么。。。

查看更多回复
提交回复