好玩遊戲
懷舊Flash遊戲
網友自造遊戲
益智謎題
討論區
站內活動
我的GS
線上人數:121
精選謎題列表
所有精選謎題
我解過的
我未解過的
其它謎題列表
所有其它謎題
近期新增
高評等
高人氣
我解過的
我未解過的
謎題分類
邏輯
數學
找規律
空間概念
快問快答
移動成立
創造力
謎語
偵探思考
眼腦並用
文字拆解圖
其他
平分12公升牛奶
- 謎題解析
回謎題解析頁
|
歷史版本
如何編輯?
用C程式跑
#include<iostream>
#include<cstdlib>
using namespace std;
int ctop[3]={12,7,5};
int c[3]={12,0,0};
bool mc1toc2(int c1n,int c2n);
int min(int a,int b);
void tryall();
int past[200][3];//c1n c2n c[c1n] c[c2n]
int pasttop=0;
void check()
{
//cout<<c[0]<<" | "<<c[1]<<" | "<<c[2]<<endl;
if( c[0]+c[1]+c[2]!=12){cout<<"12fause";cout<<endl<<"sys2";while(1)system("pause");}
if(c[0]==6||c[1]==6||c[2]==6){cout<<"GG"<<endl;
for(int i=0;i<=pasttop;i++)
{
cout<<past[i][0]<<" | "<<past[i][1]<<" | "<<past[i][2]<<" | "<<endl;
}while(1)system("pause");}
}
int main()
{
past[0][0]=12;
past[0][1]=0;
past[0][2]=0;
tryall();
cout<<endl<<"sys1";
system("pause");
}
void tryall()
{
int count=0;
if(mc1toc2(2,0)){tryall();count++;}
if(mc1toc2(2,1)){tryall();count++;}
if(mc1toc2(0,1)){tryall();count++;}
if(mc1toc2(0,2)){tryall();count++;}
if(mc1toc2(1,0)){tryall();count++;}
if(mc1toc2(1,2)){tryall();count++;}
}
bool mc1toc2(int c1n,int c2n)
{
int k;
if(c[c1n]+c[c2n]==12&&c2n==0)return false;
if(c[c1n]>0&&c[c2n]<ctop[c2n])
{
k=min(ctop[c2n]-c[c2n],c[c1n]);
c[c2n]+=k;
c[c1n]-=k;
pasttop++;
past[pasttop][0]=c[0];
past[pasttop][1]=c[1];
past[pasttop][2]=c[2];
for(int i=0;i<pasttop;i++)
if(c[0]==past[i][0] &&c[1]==past[i][1]&&c[2]==past[i][2])
{
c[c2n]-=k;
c[c1n]+=k;
pasttop--;
return false;
}
//cout<<c1n<<"to"<<c2n<<" ";
check();
return true;
}
return false;
}
int min(int a,int b)
{
if(a<b)
return a;
return b;
}
--------------------------
結果:
12 | 0 | 0 |
5 | 7 | 0 |
0 | 7 | 5 |
7 | 0 | 5 |
7 | 5 | 0 |
2 | 5 | 5 |
2 | 7 | 3 |
9 | 0 | 3 |
9 | 3 | 0 |
4 | 3 | 5 |
4 | 7 | 1 |
11 | 0 | 1 |
11 | 1 | 0 |
6 | 1 | 5 |
備註
送出