Test instructions the volume S of coke using a volume of two cups of N and M, respectively, divided into two parts, at least how many times to pour coke
The amount of Coke in the container s,n,m can be seen as a state
The containers are all without scale, so every time you pour a coke, either pour yourself out or pour it all over.
Each state can be reached by a single pour of water to which states so can be determined by BFS to reach each state need to pour how many times
3 containers with a Coke in the S/2 state is the answer, S is an odd number, it is not possible to directly ignore
#include <cstdio> #include <cstring>using namespace std;const int n = 105;int V[n][n][n], N, M, S, le, Ri;struc T State {int A, B, C, D; State () {} state (int e, int f, int g, int h): A (E), B (f), C (g), D (h) {}} q[n * N * n];void pour (int a, int b, I NT C, int d) {if (!v[a][b][c]) {v[a][b][c] = 1; q[ri++] = State (A, B, C, D + 1); }}int BFS () {int A, B, C, D; Le = ri = 0; q[ri++] = State (s, 0, 0, 0); memset (V, 0, sizeof (v)); V[s][0][0] = 1; while (Le < RI) {a = q[le].a, B = q[le].b, c = q[le].c, d = q[le++].d; if (a = = S/2 | | b = S/2 | | c = = S/2) return D + (a && b && c! = 0); Pour (a-n + b, N, c, D); S->n:pour (a-m + C, B, M, d); s->m; Pour (a + B, 0, C, D); n->s; Pour (a + C, B, 0, D); m->s; if (b > M-c) pour (A, b-m + C, M, d); N->m else pour (a, 0, B + C, D); if (C > N-b) pour (A, n, c-n + B, D); M->n else pour (a, B + C, 0, D); } return 0;} int main () {int ans; while (scanf ("%d%d%d", &s, &n, &m), n) {ans = 0; if (s% 2 = = 0) ans = BFS (); if (!ans) puts ("NO"); else printf ("%d\n", ans); } return 0;}
very Coke .
problem DescriptionIt is a pleasant thing to drink coke after exercise, but Seeyou doesn't think so. Because every time when Seeyou bought Coke, Ox asked to share this bottle of Coke with seeyou, and must drink as much as seeyou. But Seeyou's hands only two cups, their capacity is N ml and M ml cola volume for S (s<101) ml (just fill a bottle), they can pour coke between three each other (there is no scale, and s==n+m,101>s>0,n>0,m>0). Smart Acmer, do you think they can split it? If you can output the minimum number of Coke, if you cannot output "no".
Inputthree integers: the volume of S Cola, N and M is the capacity of two cups, ending with "0 0 0".
OutputIf you can divide it, please output a minimum number of times, otherwise output "NO".
Sample Input
7 4 34 1 30 0 0
Sample Output
NO3
HDU 1495 very coke (BFS pour water problem)