算法题:UVA 10717 Mint(多个数最小公倍数)

Problem E: Mint

The Royal Canadian Mint has commissioned a new series of designer coffee tables, with legs that are constructed from stacks of coins. Each table has four legs, each of which uses a different type of coin. For example, one leg might be a stack of quarters, another nickels, another loonies, and another twonies. Each leg must be exactly the same length.

Many coins are available for these tables, including foreign and special commemorative coins. Given an inventory of available coins and a desired table height, compute the lengths nearest to the desired height for which four legs of equal length may be constructed using a different coin for each leg.

Input consists of several test cases. Each case begins with an integers: 4 <= n<= 50 giving the number of types of coins available, and 1 <= t <= 10 giving the number of tables to be designed. n lines follow; each gives the thickness of a coin in hundredths of millimetres. t lines follow; each gives the height of a table to be designed (also in hundredths of millimetres). A line containing 0 0 follows the last test case.

For each table, output a line with two integers: the greatest leg length not exceeding the desired length, and the smallest leg length not less than the desired length.

Sample Input

4 2

50

100

200

400

1000

2000

0 0

Output for Sample Input

800 1200

2000 2000

时间: 2024-08-22 14:21:50

算法题:UVA 10717 Mint(多个数最小公倍数)的相关文章

UVa 10717 Mint:DFS枚举4个数的lcm

10717 - Mint Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1658 The Royal Canadian Mint has commissioned a new series of designer coffee tables, with l

算法题之UVA 763

Fibinary Numbers The standard interpretation of the binary number 1010 is 8 + 2 = 10. An alternate way to view the sequence ``1010'' is to use Fibonacci numbers as bases instead of powers of two. For this problem, the terms of the Fibonacci sequence

算法题:uva 10318

题目链接: 首先,可以确定每个格子只能选一次,因为选任何大于0的偶数次,等于没有效果 一样. 然后,就可以把这题理解成从r*c的矩阵中选择一些格子进行"点亮"操作,使得最终所 有格子都是"亮"的状态.那么,每个格子要么有点亮操作,要么没有,总共复杂度为2^25,显然必须 进行减枝. 假设从第一行第一列开始,从左往右,从上往下一次依次选择,对于当前所在位置( x, y),它已经不能影响到x-2以前的行数了,所以当到x行时,如果第x-2行没有全部点亮,则进行减枝 . 此

算法题:uva 1330

题目链接: http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=460&page=show_problem&problem=4076 以前做过一道一维的,这题只是变成了二维的,其他方法都一样.HDU 1506  Largest Rectangle in a Histogram   题解 代码1: #include<cstdio> #include<cs

百度知道-【java算法题】凑凑凑凑凑凑字数

问题描述 [java算法题]凑凑凑凑凑凑字数 题目:标题:猜字母???把abcd...s共19个字母组成的序列重复拼接106次,得到长度为2014的串.???接下来删除第1个字母(即开头的字母a),以及第3个,第5个等所有奇数位置的字母.??得到的新串再进行删除奇数位置字母的动作.如此下去,最后只剩下一个字母,请写出该字母./-----------------------------------从百度知道查看但是不懂 1024 和他的思维求大神解惑 /----------------------

求助一道二维数组交换特定元素位置的算法题,谢谢大家!

问题描述 求助一道二维数组交换特定元素位置的算法题,谢谢大家! 刚试验了一下出了新问题- - 比如,一开始是左边的数组,我想"把2个0去掉,然后0上面的2就掉下来了",形成右边的新数组 然后我用了循环遍历,比如只看第二列,我的做法是"从下往上找,遇到0,就和0上面的数字交换",结果成了下面这个样子了- - 我有个改进想法是"还是从下往上找,遇到0之后判断上面的是不是0,如果是0,再继续向上再找,直到不是0,然后把这个数赋值给一开始那个0的位置",

经典算法题每日演练——第十七题 Dijkstra算法

原文:经典算法题每日演练--第十七题 Dijkstra算法         或许在生活中,经常会碰到针对某一个问题,在众多的限制条件下,如何去寻找一个最优解?可能大家想到了很多诸如"线性规划","动态规划" 这些经典策略,当然有的问题我们可以用贪心来寻求整体最优解,在图论中一个典型的贪心法求最优解的例子就莫过于"最短路径"的问题.   一:概序    从下图中我要寻找V0到V3的最短路径,你会发现通往他们的两点路径有很多:V0->V4-&g

基础算法题,求思路和代码

问题描述 基础算法题,求思路和代码 问题 E: L1-6. 连续因子 时间限制: 1 Sec 内存限制: 128 MB 题目描述 一个正整数N的因子中可能存在若干连续的数字.例如630可以分解为3*5*6*7,其中5.6.7就是3个连续的数字.给定任一正整数N,要求编写程序求出最长连续因子的个数,并输出最小的连续因子序列. 输入 输入在一行中给出一个正整数N(1<N<231). 输出 首先在第1行输出最长连续因子的个数:然后在第2行中按"因子1*因子2*--*因子k"的格式

面试题-今天朋友去面试看到一个算法题,求解

问题描述 今天朋友去面试看到一个算法题,求解 如题,完全没思路啊orz求指教,按照题目推测似乎是一个两个数之间距离为自身进行排序的算法,但是具体实现完全没思路,实在不行求个算法名也好啊orz 解决方案 public class Test { int n = 4; int[] arr = new int[2*n]; public void init(){//初始化 for(int i = 0; i<2*n; i++){ arr[i] = -1; } } public void sort(int g