




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上十二硬幣判別代碼 人間客制作國外流行的12個硬幣問題:12硬幣中可能有一個假的,而且不知道假幣比真幣重還是輕,給你一架天平,天平?jīng)]有示數(shù),只能判斷是平衡還是不平,且只準稱三次,讓你判斷是否有假幣;如果有,找出來。解法思想如下:第一步:任選8個比較,如選: 比 一、若一樣重,則假幣在中,第二步: 比1.若一樣重,則可能的假幣為。則第三步: vs 1)若一樣重,則沒有假幣;2)不一樣重,則假幣為:如果(1)>(12),則假幣輕,反之,假幣重; 2.若重,則第三步: 比 1)若一樣重,則假幣為(較輕)2)不一樣重,則假幣為、中較重者3.若輕,則第三步: 比 1)若一樣
2、重,則假幣為(較重)2)不一樣重,則假幣為、中較輕者二、若重,則第二步: 比 1.若一樣重,則假幣在中,第三步: 比 假幣為、中較輕者2.若端較重,則假幣在中,第三步:比 1)若一樣重,則假幣為(較輕)2)不一樣重,則假幣為中較重者3.若端較重,則假幣在中,第三步: 比 1)若一樣重,則假幣為(較輕)2)不一樣重,則假幣為、中較重者三、若輕,則與上面類似,第二步:比 1.若一樣重,則假幣在中,第三步: 比 假幣為、中較重者2.若端較輕,則假幣在中,第三步: 比 1)若一樣重,則假幣為(較重)2)不一樣重,則假幣為中較輕者3.若端較輕,則假幣在中,第三步: 比 1)若一樣重,則假幣為(較重)2)
3、不一樣重,則假幣為、中較輕者在科技發(fā)達的時代,我們都不愿意去做這樣繁瑣的比較,而是想借助于計算機的威力,下面給大家介紹一種方法,可以在很短的時間內(nèi)完成中比較。當然,這類問題轉(zhuǎn)化到編程上去后,主要考查的是大家的編程思想,而不再是12硬幣問題本身了,因為12個硬幣的重量需要大家自己去輸入,這些數(shù)據(jù)只是為了檢驗大家程序的正確與否。下面是該問題的代碼:#include <stdio.h>void main()int i;float a12;for(i=0;i<12;i+)scanf("%f",&ai);if(a0+a1+a2+a3=a4+a5+a6+a7)
4、 if(a0+a1+a2=a8+a9+a10) if(a8=a11) printf("There is no special coin!n"); else if(a8>a11) printf("There is a special coin:%f(12) and it's lighter than others.n",a11); else printf("There is a special coin:%f(12) and it's heavier than others.n",a11); else if(a0+
5、a1+a2>a8+a9+a10) if(a8=a9) printf("There is a special coin:%f(11) and it's lighter than others.n",a10); else if(a8>a9) printf("There is a special coin:%f(10) and it's lighter than others.n",a9); else printf("There is a special coin:%f(9) and it's lighter th
6、an others.n",a8); else if(a8=a9) printf("There is a special coin:%f(11) and it's heavier than others.n",a10); else if(a8>a9) printf("There is a special coin:%f(9) and it's heavier than others.n",a8); else printf("There is a special coin:%f(10) and it's he
7、avier than others.n",a9); else if(a0+a1+a2+a3>a4+a5+a6+a7) if(a0+a2+a5=a1+a4+a8) if(a6=a7) printf("There is a special coin:%f(4) and it's heavier than others.n",a3); else if(a6>a7) printf("There is a special coin:%f(8) and it's lighter than others.n",a7); else
8、printf("There is a special coin:%f(7) and it's lighter than others.n",a6); else if(a0+a2+a5>a1+a4+a8) if(a0=a2) printf("There is a special coin:%f(5) and it's lighter than others.n",a4); else if(a0>a2) printf("There is a special coin:%f(1) and it's heavier
9、than others.n",a0); else printf("There is a special coin:%f(3) and it's heavier than others.n",a2); else if(a1>a8) printf("There is a special coin:%f(2) and it's heavier than others.n",a1); if(a5<a8) printf("There is a special coin:%f(6) and it's light
10、er than others.n",a5); else if(a0+a2+a5=a1+a4+a8) if(a6=a7) printf("There is a special coin:%f(4) and it's lighter than others.n",a3); else if(a6>a7) printf("There is a special coin:%f(7) and it's heavier than others.n",a6); else printf("There is a special co
11、in:%f(8) and it's heavier than others.n",a7); else if(a0+a2+a5<a1+a4+a8) if(a0=a2) printf("There is a special coin:%f(5) and it's heavier than others.n",a4); else if(a0>a2) printf("There is a special coin:%f(3) and it's lighter than others.n",a2); else printf("There is a special coin:%f(1) and it's lighter than others.n",a0); else if(a1<a8) printf("There is a spe
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度住房轉(zhuǎn)租合同模板(含押金退還流程)
- 二零二五年度在線醫(yī)療咨詢消費合同協(xié)議
- 二零二五年度人工智能增資合作協(xié)議
- 二零二五年度醫(yī)院護士輔助人員雇傭協(xié)議
- 2025年度高品質(zhì)住宅房東租房合同及物業(yè)服務協(xié)議
- 定制玻璃家具協(xié)議
- 養(yǎng)生產(chǎn)品采購合同
- 二零二五年度人工智能應用融資顧問協(xié)議
- 二零二五年度金融衍生品交易股份代持合作協(xié)議
- 2025年度智慧農(nóng)業(yè)項目融資合作框架協(xié)議范本
- 中西醫(yī)結(jié)合腫瘤學試卷
- 一年級下冊勞動課教案5篇
- 特殊工種操作人員體檢表
- 常用橋牌詞語(中英文對照)
- 加盟招商方案PPT模板
- 中石油HSE培訓試題集(共33頁)
- 雙碳視角看歐盟綠色新政政策篇
- 噴(烤)漆房VOCs治理設施日常運行臺賬
- 往復式壓縮機組單機試運方案
- 區(qū)域環(huán)境概況
- 爆破片面積計算
評論
0/150
提交評論