資源簡介
碩士人工智能課程作業資源包,包含了12硬幣(12coins)源程序和README文檔,而且包含了上課時用需要演講使用的PPT幻燈片,還有兩篇關于12硬幣的論文可以參考閱讀。12硬幣問題的描述:有12個硬幣,已知有一個是不標準的(不能確定是輕還是重),要求使用天平最多3次,找出那個不標準的硬幣,并確定是輕的還是重的。

代碼片段和文件信息
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStreamReader;
import?java.util.*;
public?class?Coins
{
/*?五元組中每個元素依次代表{LHSLSHSST}.
?*? 標準型(Standard)標記為S
輕標型(Light?or?Standard)標記為LS
重標型(Heavy?or?Standard)標記為HS
輕重標準型(Light?or?Heavy?or?Standard)標記為LHS
已經稱量的次數?標記為T
*/
//創建數組中要用的下標值
static?int?lhs?=?0;
static?int?ls?=?1;
static?int?hs?=?2;
static?int?s?=?3;
static?int?t?=?4;
//?創建未知硬幣的個數
static?int?uncertainty?=?12;
//?創建目標狀態五元組設置最多利用天平的次數
static?int?limit?=?3;?
//?設置一個結點記錄值,本來想用一個int值就行了,不過我要add到nodeRecord集合后面,必須add整型數組,我也懶得改了,就直接把標記設成整型數組。
static?int[]?notExist?=?{-1};
static?int[]?notknow={0};
static?int[]?success?=?{1};
static?int[]?fail?=?{2};
static?int[]?sameSituation?=?{3};
// ?創建測試狀態組,測試天平方案
static?int[]?testState=?{39?0?0?0?0};
static?int[]?testleft?=?{13000};
static?int[]?testright?=?{13000};
/**
?*?@param?args
?*/
public?static?void?main(String[]?args)
{
while?(true)
{
//?TODO?Auto-generated?method?stub
//?用于保留遍歷過的結點的列表,其中[狀態元組+左盤分配元組+右盤分配元組+結點標記值],簡寫【狀態+方案】列表。
ArrayList?List?=?new?ArrayList();
System.out.print(“請輸入未知硬幣的個數:“);
try
{
???InputStreamReader?temp=new?InputStreamReader(System.in);
???BufferedReader?input=new?BufferedReader(temp);?
// ???System.out.println(input.readLine());
???uncertainty?=?Integer.valueOf(input.readLine());
}
catch?(IOException?e)
{
???e.printStackTrace();
}
System.out.print(“請輸入稱量次數:“);
try
{
InputStreamReader?temp=new?InputStreamReader(System.in);
BufferedReader?input=new?BufferedReader(temp);?
// System.out.println(input.readLine());
limit?=?Integer.valueOf(input.readLine());
}
catch?(IOException?e)
{
e.printStackTrace();
}
//?創建初始狀態五元組
int[]?initialState?=?{uncertainty0000};
//?創建目標狀態五元組
// int[]?goalState1?=?{010uncertainty-1limit};
// int[]?goalState2?=?{001uncertainty-1limit};
//?最初狀態賦值給當前狀態。
int?[]?currentState?=?initialState;
long?t1=System.currentTimeMillis();
//運行測試內容
// 構造第一個結點。
boolean?isok?=?checkThisState(ListcurrentState);
long?t2=System.currentTimeMillis();
System.out.println(“\n尋找解決方案的過程中產生的所有狀態都保存在列表中...“);
showWaytoGoal(ListinitialState);
System.out.print(“\n\n運行時間為:“+(t2-t1)+“毫秒!“);
if?(isok)
{
System.out.print(“\n從“+uncertainty+“個未知硬幣中通過使用“+limit+“次天平找假硬幣,有解!“);
}
else?{
System.out.print(“\n從“+uncertainty+“個未知硬幣中通過使用“+limit+“次天平找假硬幣,無解!“);
}
// System.out.println(“列表中成功的【狀態+方案】結點有多少個?“+triumph);
// System.out.println(“記錄中成功路徑有多少條?“+ways);
System.out.println();
System.out.println();
System.out.println();
try
{
Thread.sleep(1000);
}
catch?(InterruptedException?e1)
{
//?TODO?Auto-generated?catch?block
e1.printStackTrace();
}
System.out
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????.CA....????171254??2011-05-09?10:37??十二硬幣問題的進一步求解.pdf
????.CA....????278449??2011-05-09?15:20??用AO算法求解一個智力難題.pdf
????.CA....????113152??2011-05-18?22:36??12硬幣.ppt
?????文件???????9996??2011-06-03?20:00??Coins.class
?????文件??????29384??2011-06-03?19:10??Coins.java
?????文件?????216576??2011-06-03?19:50??CoinsCheck.exe
????.CA....????187392??2013-01-29?14:28??Readme.doc
-----------?---------??----------?-----??----
??????????????1006203????????????????????7
- 上一篇:FbHashCal.apk
- 下一篇:Eviews9.0安裝包及破解文件
評論
共有 條評論