poj 3414 bfs 물 문제 인 데 귀찮아 요.
7415 단어 poj
용기 a, 용기 b, 그리고 용량 c 를 드 립 니 다.-- 제 한 된 절 차 를 통 해 c 의 목표 상 태 를 달성 할 수 있 을 까?
음, path 배열 에 관 해 서 는 사실 또 대신 을 참조 하 는 것 은 너무 느끼 해서 조작 6 가 지 를 해 칠 수 밖 에 없다. 1. a FILL (1) 을 가득 채 우 고 2. b FILL (2) 을 가득 채 우 고 3. a DROP (1) 를 비우 고 4. b DROP (2) 를 비우 고 5. A 를 B POUR (1, 2) 에 붓는다.
알고리즘: bfs, 플러스 그룹? ps and 인내심, 즉 문 제 를 다 쓰 는 인내심 과 잘못 고 치 는 인내심 [울 음]
다음은 codes 입 니 다.
poj 3414
228k 0ms
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int m,n,k;
int vis[105][105];
char opr[20][20]= {"FILL(1)" , "FILL(2)" , "DROP(1)" , "DROP(2)" , "POUR(1,2)" , "POUR(2,1)" }; // 6
struct node
{
int x,y,step;//
int path[200]; // //!!
};
void bfs( )
{
int i,j;
int kx,ky;
memset(vis,0,sizeof(vis));
queue<node>q;
node now,next;//
now.x=0;
now.y=0;
now.step=0;
q.push(now);
vis[0][0]=1;
while(!q.empty())
{
now=q.front();
q.pop();
if(now.x==k||now.y==k)//
{
printf("%d
",now.step);
for( i=1; i<=now.step; i++)
{
printf("%s
",opr[now.path[i]]);
}
return;
}
for(i=1; i<=6; i++) //
{
if(i == 1 ) // , 1;
{
next.y=now.y;
next.x=m;
now.path[now.step+1]=0;
}
else if(i == 2)//sec,fill 2
{
next.x=now.x;
next.y=n;
now.path[now.step+1]=1;
}
else if(i == 3)//third,drop 1;
{
next.y=now.y;
next.x=0;
now.path[now.step+1]=2;
}
else if(i == 4)// fourth,drop 2
{
next.x=now.x;
next.y=0;
now.path[now.step+1]=3;
}
else if(i == 5)
{
if(n-now.y>now.x) // pour
{
next.x=0;
next.y=now.x+now.y;
}
else
{
next.y=n;
next.x=now.x-n+now.y;
}
now.path[now.step+1]=4;
}
else if(i == 6)
{
if(m-now.x>now.y)//
{
next.y=0;
next.x=now.x+now.y;
}
else//
{
next.x=m;// m
next.y=now.y-m+now.x;
}
now.path[now.step+1]=5;
}
if(vis[next.x][next.y] == 1)
continue;
vis[next.x][next.y]=1;
next.step=now.step+1;
for(j=1; j<=next.step; j++) //!!!!!! operation,
{
next.path[j]=now.path[j];
}
q.push(next);
}
}
printf("impossible
");
return;
}
int main()
{
int i;
scanf("%d%d%d",&m,&n,&k);
bfs();
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
POJ3071: Football(확률 DP)Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. After n rounds, only one team...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.