HDU 1495 非常可乐——bfs
来源:互联网 发布:核盾网络验证使用方法 编辑:程序博客网 时间:2024/06/11 04:47
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <queue>using namespace std;const int maxn = 110;bool vis[maxn][maxn][maxn];int S, A, B;struct State { int s, a, b, step;}state;queue<State> q;void solve(int &x, int X, int &y, int Y) { if (X - x <= y) { y = y - X + x; x = X; } else { x = x + y; y = 0; }}void add(int s, int a, int b, int step) { if (!vis[s][a][b]) { vis[s][a][b] = true; q.push(State{s, a, b, step}); }}void bfs() { int target = S>>1, ans = -1; memset(vis, false, sizeof(vis)); vis[S][0][0] = true; while (!q.empty()) q.pop(); q.push(State{S, 0, 0, 0}); while (!q.empty()) { state = q.front(); q.pop(); if (state.s == target && state.a == target) { ans = state.step; break; } int s, a, b; s = state.s, a = state.a, b = state.b; solve(a, A, s, S); add(s, a, b, state.step + 1); s = state.s, a = state.a, b = state.b; solve(b, B, s, S); add(s, a, b, state.step + 1); s = state.s, a = state.a, b = state.b; solve(b, B, a, A); add(s, a, b, state.step + 1); s = state.s, a = state.a, b = state.b; solve(s, S, a, A); add(s, a, b, state.step + 1); s = state.s, a = state.a, b = state.b; solve(s, S, b, B); add(s, a, b, state.step + 1); s = state.s, a = state.a, b = state.b; solve(a, A, b, B); add(s, a, b, state.step + 1); } if (ans == -1) printf("NO\n"); else printf("%d\n", ans);}int main() { while (~scanf("%d %d %d", &S, &A, &B) && (S || A || B)) { if (A < B) swap(A, B); if (S % 2) printf("NO\n"); else bfs(); } return 0;}
阅读全文
1 0
- hdu 1495——非常可乐(BFS)
- HDU 1495——非常可乐( BFS )
- HDU 1495 非常可乐——bfs
- (step4.2.5)hdu 1495(非常可乐——BFS)
- hdu 1495 bfs 非常可乐
- hdu 1495 非常可乐 BFS
- hdu 1495 非常可乐 bfs
- hdu 1495 非常可乐 (bfs)
- 非常可乐 hdu 1495 BFS
- hdu 1495非常可乐 bfs
- HDU 1495 非常可乐 BFS
- hdu 1495 非常可乐 (bfs)
- [bfs] HDU 1495 非常可乐
- BFS-HDU-1495-非常可乐
- hdu 1495 非常可乐(BFS)
- HDU 1495 非常可乐 (BFS)
- HDU 1495 非常可乐 (BFS)
- HDU 1495--非常可乐【BFS】
- 互联网产品用户体验的层次详解
- Spring bean提供了3中注入方式
- Windows Server 2016正式版教程:安装、激活、设置
- 通过JDBC访问数据库的基本步骤
- Qt::TOOL窗口关闭但进程仍在运行解决方案
- HDU 1495 非常可乐——bfs
- 34 Three.js的材质THREE.MeshDepthMaterial
- sicp 练习2.4
- c++筛选法素数(任意a,b区间内的素数)
- 读史笔记——秦史
- [LeetCode Solution 98]: Validate Binary Search Tree
- [转]windows下安装Python虚拟环境virtualenvwrapper-win
- 如何用消息系统避免分布式事务?
- JBOSS配置文档