2014
03-06

# 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.

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.

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

/**
* ID: ping128
* LANG: C++
*/

#include <stdio.h>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <math.h>
#include <algorithm>
#include <map>
#include <string.h>

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;
typedef pair<PII, int>PII2;

int n;
class Solve
{
public:
void main2()
{
printf("%d pencils for %d cents\n", n, n);
int cnt = 0;

for(int i = 1; i <= n; i++ )
for(int j = 1; i + j <= n; j++ )
{
if((100 * n - (400 * i + 50 * j)) % 25 == 0 && (100 * n - (400 * i + 50 * j)) / 25 + i + j == n && (100 * n - (400 * i + 50 * j)) / 25 > 0)
{
cnt = 1;
printf("%d at four cents each\n%d at two for a penny\n%d at four for a penny\n", i, j, (100 * n - (400 * i + 50 * j)) / 25);
printf("\n");
}
}

if(cnt == 0) printf("No solution found.\n\n");
}
};

int main()
{
// freopen("D.in", "r", stdin);
// freopen(".out", "w", stdout);

int t = 0;
while(1)
{
t++;
cin >> n;
if(n == 0) break;
printf("Case %d:\n", t);
Solve ___test;
___test.main2();
}
//while(1);
return 0;
}

1. simple, however efficient. A lot of instances it is difficult to get that a??perfect balancea?? among usability and appearance. I must say that youa??ve done a exceptional task with this. Also, the blog masses quite fast for me on Web explore.

2. #include <stdio.h>
int main()
{
int n,p,t[100]={1};
for(int i=1;i<100;i++)
t =i;
while(scanf("%d",&n)&&n!=0){
if(n==1)
printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
else {
if(n%4) p=n/4+1;
else p=n/4;
int q=4*p;
printf("Printing order for %d pages:n",n);
for(int i=0;i<p;i++){
printf("Sheet %d, front: ",i+1);
if(q>n) {printf("Blank, %dn",t[2*i+1]);}
else {printf("%d, %dn",q,t[2*i+1]);}
q–;//打印表前
printf("Sheet %d, back : ",i+1);
if(q>n) {printf("%d, Blankn",t[2*i+2]);}
else {printf("%d, %dn",t[2*i+2],q);}
q–;//打印表后
}
}
}
return 0;
}

3. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.

4. 嗯 分析得很到位，确实用模板编程能让面试官对你的印象更好。在设置辅助栈的时候可以这样：push时，比较要push的elem和辅助栈的栈顶，elem<=min.top()，则min.push(elem).否则只要push（elem）就好。在pop的时候，比较stack.top()与min.top(),if(stack.top()<=min.top()),则{stack.pop();min.pop();}，否则{stack.pop();}.