【每日一题】Pots

Pots

题意:

倒水,来回倒,自己看吧

题解:

参考《非常可乐》,原理挺简单的

个人问题:

我,TMD,一直WA,参考无数代码,还是WA,心态炸了!

代码:
///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;
}
写在最后:

推荐两篇博客个人关于搜索的总结关于这个题一位同学的题解

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值