[Una pregunta por día] Ollas

Ollas

Tema:

Vierta agua, vierta de un lado a otro, compruébelo usted mismo

Solución:

Consulte "Muy Coca-Cola", el principio es bastante simple

Problemas personales:

Yo, TMD, he sido WA, me refiero a innumerables códigos, aún WA, ¡la mentalidad ha explotado!

Código:
///Pots(WA)
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stdio.h>
#include<string.h>
using namespace std;
struct xiao {
    int x, y, k;
}now, well;
int a, b, s = 0, mink = 100,C;
int flag[100][100], brr[10][10], ans[100000], minn[100];
int BFS(int a,int b){
    memset(flag, 1, sizeof(flag));
    xiao A;
    A.x = 0;
    A.y = 0;
    A.k = 0;
    queue<xiao> Q;
    Q.push(A);
    flag[A.x][A.y] = 0;
    while (!Q.empty()) {
        now = Q.front();///处理第一个数据
        Q.pop();///抛弃第一个数据
        if (now.x == C || now.y == C)///判断是否到达目的地
            return now.k;
        for (int i = 1; i <= 6; i++) {
            if (i == 1) { well.x = a; well.y = now.y;}
            if (i == 2) { well.x = 0; well.y = now.y;}
            if (i == 3) { well.x = now.x - b + now.y; well.y = min(b,now.x+now.y);}
            if (i == 4) { well.x = now.x; well.y = b; }
            if (i == 5) { well.x = now.x; well.y = 0; }
            if (i == 6) { well.x = min(a, now.x + now.y); well.y = now.y - a + now.x; }
            well.k = now.k * 10 + i;
            if (well.x < 0) well.x = 0;
            if (well.y < 0) well.y = 0;
            if (flag[well.x][well.y]) {
                Q.push(well);
                flag[well.x][well.y] = 0;
            }
        }
    }
    return -1;
}
int main(){
        int x, y, u = 0;
        memset(ans, 0, sizeof(ans));
        scanf("%d %d %d", &x, &y,&C);
        x = BFS(x, y);
        if (x == -1) cout << "impossible" << endl; 
        while (x > 0) {
            ans[u] = x % 10;
            x /= 10;
            u++;
        }
        cout << u << endl;
        for (int i = u - 1; i >= 0; i--) {
            if (ans[i] == 1) printf("FILL(1)\n" );
            if (ans[i] == 2) printf("DROP(1)\n");
            if (ans[i] == 3) printf("POUR(1,2)\n");
            if (ans[i] == 4) printf("FILL(2)\n" );
            if (ans[i] == 5) printf("DROP(2)\n");
            if (ans[i] == 6) printf("POUR(2,1)\n");
        }
    return 0;
}
Escribe al final:

Recomiende dos resumen personal del blog sobre búsqueda , la solución de un estudiante para este problema .

Publicado 41 artículos originales · elogiado 16 · visitas 1462

Supongo que te gusta

Origin blog.csdn.net/weixin_43824551/article/details/104932519
Recomendado
Clasificación