主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3153

Problem Description
Before "automaton" was a theoretic computer science concept, it meant "mechanical figure or contrivance constructed to act as if by its own motive power; robot." Examples include fortunetellers, as shown above, but could also describe a pencil seller, moving pencils from several baskets to a delivery trough.


On National Public Radio, the Sunday Weekend Edition program has a "Sunday Puzzle" segment. The show that aired on Sunday, 29 June 2008, had the following puzzle for listeners to respond to (by Thursday, 3 July, at noon through the NPR web site):

  • From a 19

th century trade card advertising Bassetts Horehound Troches, a remedy for coughs and colds: A man buys 20 pencils for 20 cents and gets three kinds of pencils in return. Some of the pencils cost four cents each, some are two for a penny and the rest are four for a penny. How many pencils of each type does the man get?One clarification from the program of 6 July: correct solutions contain at least one of each pencil type.


For our purposes, we will expand on the problem, rather than just getting 20 pencils for 20 cents (which is shown in the sample output below). The input file will present a number of cases. For each case, give all solutions or print the text "No solution found". Solutions are to be ordered by increasing numbers of four-cent pencils.

Input
Each line gives a value for N (2 <= N <= 256), and your program is to end when N = 0 (at most 32 problems).
Output
The first line gives the instance, starting from 1, followed by a line giving the statement of the problem. Solutions are shown in the three-line format below followed by a blank line, or the single line "No solution found", followed by a blank line. Note that by the nature of the problem, once the number of four-cent pencils is determined, the numbers of half-cent and quarter-cent pencils are also determined.

Case n:
nn pencils for nn cents
nn at four cents each
nn at two for a penny
nn at four for a penny

Sample Input
10 20 40 0
Sample Output
Case 1: 10 pencils for 10 cents No solution found. Case 2: 20 pencils for 20 cents 3 at four cents each 15 at two for a penny 2 at four for a penny Case 3: 40 pencils for 40 cents 6 at four cents each 30 at two for a penny 4 at four for a penny 7 at four cents each 15 at two for a penny 18 at four for a penny
Source
2008 ACM-ICPC Pacific Northwest Region

代码例如以下:

#include<cstdio>
int main()
{int n;int flag;int cas = 0;while(scanf("%d",&n)&&n){double sum = n*1.0;flag = 0;printf("Case %d:\n",++cas);printf("%d pencils for %d cents\n",n,n);for(int i = 1; i < n; i++) //1{for(int j = 1; j < n; j++) //2{for(int k = 1; k < n; k++) //3{if(sum==i*4+j*0.5+k*0.25 && i+j+k==n){flag = 1;printf("%d at four cents each\n",i);printf("%d at two for a penny\n",j);printf("%d at four for a penny\n\n",k);}}}}if(!flag)printf("No solution found.\n\n");}return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

转载于:https://www.cnblogs.com/gcczhongduan/p/4803473.html

HDU 3153 Pencils from the 19th Century(数学)相关推荐

  1. HDU 3153 Pencils from the 19th Century(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3153 Problem Description Before "automaton" ...

  2. HDU 4741 Save Labman No.004 计算几何 数学

    题目链接 这道题会暴露很多孩纸的高数学的好不好.如何计算三维直线的最短距离和垂足的坐标,学习链接 之后的就是代入公式计算了. 1 #include <stdio.h> 2 #include ...

  3. hdu 4278 2012天津赛区网络赛 数学 *

    8进制转为10进制 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include ...

  4. HDU - 4635 Strongly connected(强连通缩点+数学+思维)

    题目链接:点击查看 题目大意:给出一个由n个点和m条边构成的无向图,现在问最多能添加几条边,能使得原图仍然不是强连通图,若原图初始时就是强连通图,直接输出-1 题目分析:首先对于原图来说,肯定会有一些 ...

  5. 转:V.I. Arnold 论数学教育

    V.I. Arnold 论数学教育 2011-03-14 08:42 V.I. Arnold 论数学教育  地点: Palais de Découverte in Paris 时间 1997年3月7日 ...

  6. 为了数学的明天,,穿越时空,重返南大(III)-

    为了数学的明天,,穿越时空,重返南大(III)     进入二十一世纪,非阿基米德数学(比如:含有无穷小的连续统)逐渐兴起,我们用该如何面对?     这是一个基本问题,必须彻底搞清楚,事实求是.   ...

  7. 陈景润定理的数学证明何处寻

    由于时代过于久远,陈景润定理的数学证明与公式推理过程很难寻找. 实际上,陈景润定理的数学证明与公式推导十分复.困难,出乎一般人的想象. 有兴趣者,可搜索该文PDF原文第,查看第5-6页.该文件共有74 ...

  8. 图示数学之: 克莱因瓶之谜

    极好的科普文章; 德国数学教授创作 http://plus.maths.org/content/os/issue26/features/mathart/index http://www.dayanza ...

  9. 【HDU - 1968】【UVA - 12096】The SetStack Computer (模拟,集合求交集并集操作,STL实现)

    题干: Background from Wikipedia: 揝et theory is a branch of mathematics created principally by the Germ ...

最新文章

  1. SDE要素类导出为shp格式文件
  2. 网易2017春招笔试真题编程题集合(2)——赶去公司
  3. linux编程下signal()函数
  4. ExpandableListView 里面嵌套GridView实现高度自适应
  5. 佛系程序员:什么bug不bug的,随缘吧
  6. 5个让IT开发效率提高200%的工具,最后一个很实用,你用过几个
  7. java mysql resultset_Java数据库——ResultSet接口
  8. iOS 三步完成购买苹果开发者账号
  9. Mac 效率工具必备神器 —— Alfred
  10. 中国省份、城市-身份证编码
  11. 设计系统测试用例时应考虑的类型
  12. 连点器---鼠标连续点击(c语言)
  13. 批处理删除文件夹命令_批处理文件夹命令
  14. 神奇的分形艺术(一):无限长的曲线可能围住一块有限的面积
  15. java stack长度_Java Stack size()用法及代码示例
  16. 微信公众平台消息接口开发(20)图片识别之人脸识别
  17. windows如何截图
  18. 关于前端更新需要清空浏览器缓存
  19. cesium 加载模型实现动画效果
  20. TypeError: Converting circular structure to JSON

热门文章

  1. JAVA打印变量类型
  2. Java 实现固定长度队列,自动删除最早添加的数据
  3. mysql通过命令添加1条数据
  4. Java Platform SE 8 中文文档
  5. JS中var、let、const区别? 用3句话概括
  6. Mac下sudo后环境变量失效的问题
  7. 资源字典——程序集之间的资源共享
  8. Android手机安全性测试手段
  9. 浮点数:一种有漏洞的抽象【译】
  10. android 精选文章