编程介的小学生 2017-02-20 14:28 采纳率: 20.5%
浏览 839
已采纳

Pencils from the 19th Century

问题描述 :

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.

Obstacle Course

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 19th 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.

Obstacle Course

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.
输入:

Each line gives a value for N (2 <= N <= 256), and your program is to end when N = 0 (at most 32 problems).
输出:

Each line gives a value for N (2 <= N <= 256), and your program is to end when N = 0 (at most 32 problems).
样例输入:

10
20
40
0
样例输出:

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

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-20 17:32
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功