




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
十二硬币判别代码 人间客制作国外流行的12个硬币问题:12硬币中可能有一个假的,而且不知道假币比真币重还是轻,给你一架天平,天平没有示数,只能判断是平衡还是不平,且只准称三次,让你判断是否有假币;如果有,找出来。解法思想如下:第一步:任选8个比较,如选: 比 一、若一样重,则假币在中,第二步: 比1.若一样重,则可能的假币为。则第三步: vs 1)若一样重,则没有假币;2)不一样重,则假币为:如果(1)(12),则假币轻,反之,假币重; 2.若重,则第三步: 比 1)若一样重,则假币为(较轻)2)不一样重,则假币为、中较重者3.若轻,则第三步: 比 1)若一样重,则假币为(较重)2)不一样重,则假币为、中较轻者二、若重,则第二步: 比 1.若一样重,则假币在中,第三步: 比 假币为、中较轻者2.若端较重,则假币在中,第三步:比 1)若一样重,则假币为(较轻)2)不一样重,则假币为中较重者3.若端较重,则假币在中,第三步: 比 1)若一样重,则假币为(较轻)2)不一样重,则假币为、中较重者三、若轻,则与上面类似,第二步:比 1.若一样重,则假币在中,第三步: 比 假币为、中较重者2.若端较轻,则假币在中,第三步: 比 1)若一样重,则假币为(较重)2)不一样重,则假币为中较轻者3.若端较轻,则假币在中,第三步: 比 1)若一样重,则假币为(较重)2)不一样重,则假币为、中较轻者在科技发达的时代,我们都不愿意去做这样繁琐的比较,而是想借助于计算机的威力,下面给大家介绍一种方法,可以在很短的时间内完成中比较。当然,这类问题转化到编程上去后,主要考查的是大家的编程思想,而不再是12硬币问题本身了,因为12个硬币的重量需要大家自己去输入,这些数据只是为了检验大家程序的正确与否。下面是该问题的代码:#include void main()int i;float a12;for(i=0;ia11) printf(There is a special coin:%f(12) and its lighter than others.n,a11); else printf(There is a special coin:%f(12) and its heavier than others.n,a11); else if(a0+a1+a2a8+a9+a10) if(a8=a9) printf(There is a special coin:%f(11) and its lighter than others.n,a10); else if(a8a9) printf(There is a special coin:%f(10) and its lighter than others.n,a9); else printf(There is a special coin:%f(9) and its lighter than others.n,a8); else if(a8=a9) printf(There is a special coin:%f(11) and its heavier than others.n,a10); else if(a8a9) printf(There is a special coin:%f(9) and its heavier than others.n,a8); else printf(There is a special coin:%f(10) and its heavier than others.n,a9); else if(a0+a1+a2+a3a4+a5+a6+a7) if(a0+a2+a5=a1+a4+a8) if(a6=a7) printf(There is a special coin:%f(4) and its heavier than others.n,a3); else if(a6a7) printf(There is a special coin:%f(8) and its lighter than others.n,a7); else printf(There is a special coin:%f(7) and its lighter than others.n,a6); else if(a0+a2+a5a1+a4+a8) if(a0=a2) printf(There is a special coin:%f(5) and its lighter than others.n,a4); else if(a0a2) printf(There is a special coin:%f(1) and its heavier than others.n,a0); else printf(There is a special coin:%f(3) and its heavier than others.n,a2); else if(a1a8) printf(There is a special coin:%f(2) and its heavier than others.n,a1); if(a5a7) printf(There is a special coin:%f(7) and its heavier than others.n,a6); else printf(There is a special coin:%f(8) and its heavier than others.n,a7); else if(a0+a2+a5a2) printf(There is a special coin:%f(3) and its lighter than others.n,a2); else printf(There is a special coin:%f(1) a
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 子宫腺肌病课件
- 工业用温度计课件
- 工业煤气安全规程培训课件
- 年后安全教育培训课件
- 威海化工安全培训课件
- 平顶山保洁安全培训课件
- 平面设计要素课件
- 平面设计基础培训课件
- Estradiol-3-d3-β-D-Glucuronide-sodium-生命科学试剂-MCE
- 2024年南昌师范学院招聘笔试真题
- 2024版公司100%股权转让协议
- T-CPIA 0056-2024 漂浮式水上光伏发电锚固系统设计规范
- 医院护理不良事件报告表
- 中医开展新技术新项目总结
- 2024年度鲁迅完整版课件
- 雪花猪养殖新模式
- 便利店设计方案
- 电力系统反恐怖知识讲座
- 铁道车辆制动装置及制动新技术全套教学课件
- 化学氧化二氧化氯氧化课件
- 为成果而管理
评论
0/150
提交评论