HDU 3153 Pencils from the 19th Century(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3153
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.
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
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
代码例如以下:
#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;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
HDU 3153 Pencils from the 19th Century(数学)的更多相关文章
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...
- HDU 5478 Can you find it 随机化 数学
Can you find it Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 2080 夹角有多大II (数学) atan(y/x)分类求角度
夹角有多大II Problem Description 这次xhd面临的问题是这样的:在一个平面内有两个点,求两个点分别和原点的连线的夹角的大小.注:夹角的范围[0,180],两个点不会在圆心出现. ...
- HDU 2050 【dp】【简单数学】
题意: 中文. 思路: 不难发现数学规律是这样的,每次增加的划分区域的数量是每次增加的交点的数量再加一.然后就总结出了递推公式. #include<stdio.h> ]; int main ...
- 题解报告:hdu 1284 钱币兑换问题(简单数学orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很 ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- hdu 4278 2012天津赛区网络赛 数学 *
8进制转为10进制 #include<cstdio> #include<iostream> #include<algorithm> #include<cstr ...
- hdu 4061 福州赛区网络赛A 数学 ***
a1/sum #include<cstdio> #include<iostream> #include<algorithm> #include<cstring ...
- HDU 5441 Travel (并查集+数学+计数)
题意:给你一个带权的无向图,然后q(q≤5000)次询问,问有多少对城市(城市对(u,v)与(v,u)算不同的城市对,而且u≠v)之间的边的长度不超过d(如果城市u到城市v途经城市w, 那么需要城市u ...
随机推荐
- [Debug] Chrome Devtools: Elements - Console Integration
The Element Inspector in Chrome DevTools offers powerful integration with the console - learn how to ...
- 关于DMA
用串口在dma中发东西的时候,,, 要判断DMA里是不是由东西,是不是在占用 当多个外设再用DMA的时候,,,要查看DMA有没有占用 一包数没发完,不要再传另一包
- vue-cli 3.x 移除console总结
网上找了很多vue-cli 3.x的配置,很多已经不适用了,把采坑的经历记录下来,供参考. 一.使用 uglifyjs-webpack-plugin 插件 配置如下: // vue.config.js ...
- Python安装后,Python IDLE等的位置
安装后,Python的目录下有如下文件:
- [PostgreSQL] Use Foreign Keys to Ensure Data Integrity in Postgres
Every movie needs a director and every rented movie needs to exist in the store. How do we make sure ...
- [Recompose] Render Nothing in Place of a Component using Recompose
Learn how to use the ‘branch’ and ‘renderNothing’ higher-ordercomponents to render nothing when a ce ...
- java判断字符串是否为数字
我们在做安卓开发中,一定会遇到判断某字符串是否是数字的问题,本文使用正则表达式可以很方便的判断出来,希望本文对安卓开发者有所帮助. 1 public boolean isNumeric(Strin ...
- Android JNI编程(四)——C语言多级指针、数组取值、从控制台输入数组
版权声明:本文出自阿钟的博客,转载请注明出处:http://blog.csdn.net/a_zhon/. 目录(?)[+] 一:前面我们介绍了一级指针的相关概念和用发,今天我们就来说一说多级指针. 1 ...
- js进阶正则表达式11RegExp的属性和方法(RegExp的属性和方法,就是RegExp对象.(点)什么的形式)(正则表达式执行之前会被编译)
js进阶正则表达式11RegExp的属性和方法(RegExp的属性和方法,就是RegExp对象.(点)什么的形式)(正则表达式执行之前会被编译) 一.总结 1. RegExp的属性和方法,就是RegE ...
- 【u005】封锁阳光大学
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 曹是一只爱刷街的老曹,暑假期间,他每天都欢快地在阳光大学的校园里刷街.河蟹看到欢快的曹,感到不爽.河蟹 ...