




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優質文檔-傾情為你奉上十二硬幣判別代碼 人間客制作國外流行的12個硬幣問題:12硬幣中可能有一個假的,而且不知道假幣比真幣重還是輕,給你一架天平,天平沒有示數,只能判斷是平衡還是不平,且只準稱三次,讓你判斷是否有假幣;如果有,找出來。解法思想如下:第一步:任選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、不一樣重,則假幣為、中較輕者在科技發達的時代,我們都不愿意去做這樣繁瑣的比較,而是想借助于計算機的威力,下面給大家介紹一種方法,可以在很短的時間內完成中比較。當然,這類問題轉化到編程上去后,主要考查的是大家的編程思想,而不再是12硬幣問題本身了,因為12個硬幣的重量需要大家自己去輸入,這些數據只是為了檢驗大家程序的正確與否。下面是該問題的代碼:#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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年新人教版部編本六班級語文上冊教學方案附教學進度支配表
- 2025年幼兒園教務工作方案
- 出鏡記者與主持人實務 課件 第十一章 融合現場
- 2025年一班級語文教學工作方案
- 2025年有創意美食節活動策劃方案
- 介紹會計行業
- 山西省太原市2024-2025學年高三上學期期末學業診斷英語試卷 含解析
- 2023年工作總結與方案
- 經內鏡染色檢查護理配合
- 配電箱產品知識培訓課件
- GB/T 18655-2025車輛、船和內燃機無線電騷擾特性用于保護車載接收機的限值和測量方法
- 吉林省吉林市2024-2025學年高三下學期3月三模試題 生物 含答案
- 2025年陜西農業發展集團有限公司(陜西省土地工程建設集團)招聘(200人)筆試參考題庫附帶答案詳解
- 遼寧省協作校2024-2025學年度下學期高三第一次模擬考試語文+答案
- 2025年03月中央社會工作部所屬事業單位公開招聘11人筆試歷年參考題庫考點剖析附解題思路及答案詳解
- 2025年中高端女裝市場趨勢與前景深度分析
- GB/T 16895.36-2024低壓電氣裝置第 7-722 部分:特殊裝置或場所的要求電動車供電
- 食品安全日管控、周排查及月調度記錄表
- 《新疆大學版學術期刊目錄》(人文社科)
- 人音版初中音樂 九年級上冊 中考一輪復習課件
- 工程制圖d唐福官第三章點直線平面的投影
評論
0/150
提交評論