2446: Mint

Time Limit(Common/Java):2000MS/20000MS     Memory Limit:65536KByte
Total Submit: 4
           Accepted:3

Description

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

Input consists of several test
cases. Each case begins with two 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.

Output

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

Sample Output

800 1200
2000 2000

给你n个数,给你个定义,问你最大和最小的距离

其实就是求下全部的四个数的最小公倍数,因为n不大,50^4还是比较小的,直接遍历一下就行的

#include<stdio.h>
#include<algorithm>
using namespace std;
const int N=3e6;
int f[N],a[];
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int main()
{
int n,t;
while(scanf("%d%d",&n,&t),n||t)
{
for(int i=; i<n; i++)
scanf("%d",&a[i]);
int b=;
for(int i=; i<n-; i++)
for(int j=i+; j<n-; j++)
{
int m=a[i]/gcd(a[i],a[j])*a[j];
for(int k=j+; k<n-; k++)
{
int mm=m/gcd(m,a[k])*a[k];
for(int l=k+; l<n; l++)
f[b++]=mm/gcd(mm,a[l])*a[l];
}
}
while(t--)
{
int q;
scanf("%d",&q);
int ma=,mi=0x3f3f3f3f;
for(int i=; i<b; i++)
if(q%f[i]==)
{
ma=mi=q;
break;
}
else
{
int x=q/f[i]*f[i];
int y=(q/f[i]+)*f[i];
ma=max(ma,x);
mi=min(mi,y);
}
printf("%d %d\n",ma,mi);
}
}
return ;
}

最新文章

  1. js导出表格数据
  2. 最值得学习的10个C语言开源项目
  3. sql 语句大小写的问题
  4. &quot;rel=nofollow&quot;属性简介
  5. 2.Spring Web MVC的优势
  6. Java内部类小程序(成员内部类,静态内部类,匿名内部类)
  7. Think in UML笔记第1章--为什么要UML
  8. why app_start start
  9. OpenStack中给wsgi程序写单元測试的方法
  10. &amp;quot;错: void 值不被忽略,因为预期&amp;quot;解决
  11. Linux多命令顺序运行
  12. css进行中打点效果
  13. Http请求封装基类HttpHelper.cs
  14. RxJava(三) flatMap操作符用法详解
  15. i春秋------Misc更新
  16. python 使用read_csv读取 CSV 文件时报错
  17. C#快速读写文件
  18. 《Python计算机视觉编程》
  19. mysql跨库联表查询
  20. Mitsubishi Lancer JDM

热门文章

  1. C#入门笔记3 表达式及运算符
  2. Java基础教程(25)--I/O
  3. map中使用await 异步函数
  4. Azure Powershell 获取可用镜像 PublisherName,Offer,Skus,Version
  5. CodeForces 219D Choosing Capital for Treeland (树形DP)
  6. Openjudge 1.13-21:最大质因子序列
  7. Web开发者必须知道的10个jQuery代码片段
  8. 各种分布(distribution)
  9. Python协程函数
  10. 关于js作用域问题详解