Usaco Section1.4 mother ' s Milk problem solving report

Source: Internet
Author: User

Milk3 Problem Solving report--icedream61 Blog Park (reproduced please specify the source)
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Topic
There are three barrels, the capacity is a, B, C, the beginning of the C bucket is full.
You can constantly pour one bucket of milk into another, but only allow it to pour over, or fill the latter, leaving the remaining milk.
Excuse me, when a bucket empty, the amount of milk in the C bucket may have what value?
"Data Range"
Integers a, B, and C are 1 to 20
"Input Format"
A B C
"Output Format"
C1 C2 C3. CN (indicates the possible capacity of the topic for C-barrels, ascending order)
"Input Sample 1"
8 9 10
"Output Example 1"
1 2 8) 9 10
"Input Sample 2"
2 5 10
"Output Example 2"
5 6 7 8 9 10
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Analysis
Direct violence search, don't try to complicate it just fine.
Three barrels all cases are at most 20x20x20=8000 species, few.
Set boolean variable P[a][b][c] Indicates whether a bucket of milk A, b barrels of milk B, c barrels Milk volume C is possible to achieve.
To begin, to make p[0][0][c]=true;
Then, start the search, each reached a new state, from this state to the six kinds of inverted method are tried, search state up to 8000 kinds, time completely enough.
Finally, look at the state of P[0][b][c], let B from 0 to 20, see C can take what values, write down, sequentially output.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Summary
Usaco evaluation really strict! Line trailing spaces are not ignored. To save some code, the first point is WA ...
AC for the second time.

--------------------------------------------------------------------------------------------------------------- ---------------------------------

Code

1 /*2 id:icedrea13 Prob:milk34 lang:c++5 */6 7#include <iostream>8#include <fstream>9 using namespacestd;Ten  One inta,b,c; A BOOLp[ +][ +][ +]; -  - voidGointAintBintc) the { -     //cout<< "Go" <<a<< "<<b<<" "<<c<<endl; -     intx, y, z -     //a->b +x=0; Y=a+b; Z=c;if(Y&GT;B) {x=y-b; y=B;} -     if(!p[x][y][z]) {p[x][y][z]=true; Go (x, y, z);} +     //a->c Ax=0; Y=b; Z=a+c;if(Z&GT;C) {x=z-c; z=C;} at     if(!p[x][y][z]) {p[x][y][z]=true; Go (x, y, z);} -     //B->a -X=a+b; y=0; Z=c;if(X>a) {y=x-a; x=A;} -     if(!p[x][y][z]) {p[x][y][z]=true; Go (x, y, z);} -     //b->c -X=a; y=0; Z=b+c;if(Z&GT;C) {y=z-c; z=C;} in     if(!p[x][y][z]) {p[x][y][z]=true; Go (x, y, z);} -     //C->a toX=a+c; Y=b; z=0;if(X>a) {z=x-a; x=A;} +     if(!p[x][y][z]) {p[x][y][z]=true; Go (x, y, z);} -     //c->b theX=a; Y=b+c; z=0;if(Y&GT;B) {z=y-b; y=B;} *     if(!p[x][y][z]) {p[x][y][z]=true; Go (x, y, z);} $ }Panax Notoginseng  - intMain () the { +Ifstreaminch("milk3.in"); AOfstream out("Milk3.out"); the  +     inch>>A>>B>>C; -  $p[0][0][c]=true; Go0,0, C); $  -     BOOLcan[ +]={}; -     intA=0; the      for(intb=0; b<=b;++b) -          for(intC=0; c<=c;++c)Wuyi             if(P[a][b][c]) can[c]=true; the  -     intC; Wu      for(c=0; c<=c;++c) -         if(Can[c]) { out<<c; Break; } About      for(++c;c<=c;++c) $         if(Can[c]) out<<" "<<C; -      out<<Endl; -  -     inch. Close (); A      out. Close (); +     return 0; the}

Usaco Section1.4 mother ' s Milk problem solving report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.