




下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(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è)硬幣問(wèn)題:12硬幣中可能有一個(gè)假的,而且不知道假幣比真幣重還是輕,給你一架天平,天平?jīng)]有示數(shù),只能判斷是平衡還是不平,且只準(zhǔn)稱三次,讓你判斷是否有假幣;如果有,找出來(lái)。解法思想如下:第一步:任選8個(gè)比較,如選: 比 一、若一樣重,則假幣在中,第二步: 比1.若一樣重,則可能的假幣為。則第三步: vs 1)若一樣重,則沒(méi)有假幣;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)然,這類問(wèn)題轉(zhuǎn)化到編程上去后,主要考查的是大家的編程思想,而不再是12硬幣問(wèn)題本身了,因?yàn)?2個(gè)硬幣的重量需要大家自己去輸入,這些數(shù)據(jù)只是為了檢驗(yàn)大家程序的正確與否。下面是該問(wè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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 上海體育大學(xué)《巖土工程項(xiàng)目管理與預(yù)算》2023-2024學(xué)年第一學(xué)期期末試卷
- 西北政法大學(xué)《法語(yǔ)精讀(Ⅱ)》2023-2024學(xué)年第一學(xué)期期末試卷
- 8道腦力測(cè)試題及答案
- 齊齊哈爾高等師范??茖W(xué)?!妒称芳庸ゎ惥C合技能訓(xùn)練》2023-2024學(xué)年第一學(xué)期期末試卷
- 2024年江蘇省連云港市贛榆實(shí)驗(yàn)中學(xué)七上數(shù)學(xué)期末預(yù)測(cè)試題含解析
- 廣州科技貿(mào)易職業(yè)學(xué)院《大學(xué)生職業(yè)發(fā)展與規(guī)劃》2023-2024學(xué)年第一學(xué)期期末試卷
- 貴州省石阡縣2024-2025學(xué)年七年級(jí)數(shù)學(xué)第一學(xué)期期末檢測(cè)模擬試題含解析
- 2024年河北省衡水中學(xué)數(shù)學(xué)七年級(jí)第一學(xué)期期末經(jīng)典模擬試題含解析
- 2024-2025學(xué)年重慶市北碚區(qū)西南大附中七年級(jí)數(shù)學(xué)第一學(xué)期期末達(dá)標(biāo)檢測(cè)試題含解析
- 安徽省合肥二中學(xué)內(nèi)地西藏班(學(xué)校)2024年七上數(shù)學(xué)期末質(zhì)量檢測(cè)試題含解析
- 高校人事檔案數(shù)字化建設(shè)實(shí)踐調(diào)研
- 2025年高中歷史會(huì)考會(huì)考全套知識(shí)復(fù)習(xí)
- 特殊作業(yè)安全管理監(jiān)護(hù)人專項(xiàng)培訓(xùn)課件
- 科幻中的物理學(xué)學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- 安全、環(huán)境、職業(yè)健康安全目標(biāo)、指標(biāo)及管理方案
- 課件:《中華民族共同體概論》第一講 中華民族共同體基礎(chǔ)理論
- 中國(guó)人民抗日戰(zhàn)爭(zhēng)勝利紀(jì)念日紀(jì)念暨世界反法西斯戰(zhàn)爭(zhēng)勝利課件
- 殯葬禮儀策劃方案
- 行政效能提升路徑研究
- (完整版)無(wú)菌醫(yī)療器械耗材生產(chǎn)企業(yè)體系文件-質(zhì)量手冊(cè)模板
- JBT 3300-2024 平衡重式叉車 整機(jī)試驗(yàn)方法(正式版)
評(píng)論
0/150
提交評(píng)論