




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上十二硬幣判別代碼 人間客制作國(guó)外流行的12個(gè)硬幣問題:12硬幣中可能有一個(gè)假的,而且不知道假幣比真幣重還是輕,給你一架天平,天平?jīng)]有示數(shù),只能判斷是平衡還是不平,且只準(zhǔn)稱三次,讓你判斷是否有假幣;如果有,找出來。解法思想如下:第一步:任選8個(gè)比較,如選: 比 一、若一樣重,則假幣在中,第二步: 比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ā)達(dá)的時(shí)代,我們都不愿意去做這樣繁瑣的比較,而是想借助于計(jì)算機(jī)的威力,下面給大家介紹一種方法,可以在很短的時(shí)間內(nèi)完成中比較。當(dāng)然,這類問題轉(zhuǎn)化到編程上去后,主要考查的是大家的編程思想,而不再是12硬幣問題本身了,因?yàn)?2個(gè)硬幣的重量需要大家自己去輸入,這些數(shù)據(jù)只是為了檢驗(yàn)大家程序的正確與否。下面是該問題的代碼:#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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 新編超市合同6篇
- 怎樣將設(shè)計(jì)成果轉(zhuǎn)化為商業(yè)價(jià)值
- 2025西南大學(xué)輔導(dǎo)員考試試題及答案
- 健康促進(jìn)與健康教育課件
- 生理衛(wèi)生保健知識(shí)講座
- T/ZGZS 0303-2023再生工業(yè)鹽硫酸鈉
- 幼兒園指甲衛(wèi)生
- 咖啡店畢業(yè)設(shè)計(jì)
- 校園社團(tuán)管理系統(tǒng)前端設(shè)計(jì)
- 創(chuàng)傷現(xiàn)場(chǎng)急救課件
- 河南省安陽市(百師聯(lián)盟)2023-2024學(xué)年高一下學(xué)期5月大聯(lián)考數(shù)學(xué)試題(人教版)(解析版)
- 2025年度幼兒園教師編制考試全真模擬試題及答案(共五套)
- 新媒體業(yè)務(wù)面試題及答案
- 廣東省廣州市2025年中考地理模擬測(cè)試卷(含答案)
- 食堂應(yīng)急預(yù)案管理制度
- 中級(jí)財(cái)務(wù)會(huì)計(jì)-中級(jí)財(cái)務(wù)會(huì)計(jì)復(fù)習(xí)學(xué)習(xí)資料
- 基于《山海經(jīng)》神祇形象的青少年解壓文具設(shè)計(jì)研究
- 安全生產(chǎn)法律法規(guī)基本知識(shí)
- 2025年新高考?xì)v史預(yù)測(cè)模擬試卷黑吉遼蒙卷(含答案解析)
- 2025高考語文名校作文題立意與例文參考11篇
- 2025年高三語言復(fù)習(xí)【文字運(yùn)用題】專項(xiàng)練習(xí)卷附答案解析
評(píng)論
0/150
提交評(píng)論