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 ;
}

TOJ 2446: Mint的更多相关文章

  1. 种类并查集,TOJ(1706)

    题目链接:http://acm.tju.edu.cn/toj/showp1706.html 很类似Poj的一道帮派的问题,记得找到的可疑的关系,不要将集合刷新就可以了. 1706.   A Bug's ...

  2. 在Linux Mint上安装node.js和npm

    1.安装Node.js 前端开发过程中,很多项目使用npm的http-server的模块来运行一个静态的服务器,我个人在Dell的笔记本上安装的是Linux Mint最新版本,所以想尝试一下在Linu ...

  3. 在Ubuntu和Linux Mint上安装Oracle JDK

    在Ubuntu和Linux Mint上安装Oracle JDK 使用下面的命令安装,只需一些时间,它就会下载许多的文件,所及你要确保你的网络环境良好: sudo add-apt-repository ...

  4. Mint linux 自定义上下文菜单实现ZIP压缩文件无乱码解压

    1. 前提条件 我的Mint Linux 是Thunar文件管理器(默认的). 2. 配置自定义动作 打开Thunar文件管理器,点击菜单“编辑”=>“配置自定义动作”.点击“+”添加一个新的. ...

  5. 解决:Win 10 + Mint 18双系统时间不同步,更换系统启动项顺序

    1.win10 & mint 18双系统时间同步: 先打开终端下更新一下时间,确保时间无误: sudo apt-get install ntpdate sudo ntpdate time.wi ...

  6. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  7. 安装Linux Mint

    1.尽量选择trusty的安装版本,kde和xfce不支持Win+..快捷键,推荐cinnamon:制作安装U盘后,选择非EFI模式启动:选择start Linux Mint(就是第一项): 2.In ...

  8. Linux Mint 17使用小结

    用过蛮多的linux系统 linux mint是我比较喜欢和常用的一个系统,装的是linux mint xfce 64位版本,在这里记录使用中遇到的一些问题及解决的方法,备忘,方便以后查看. 1.首先 ...

  9. Linux mint 18版本开启SSH服务

    linux mint 18版本默认是没有安装ssh server的 需要手动安装 安装ssh server: 此命令需要联网,会自动下载安装 安装之后看是否开始了ssh, 看到ssh-agent 和s ...

随机推荐

  1. 实现如下语法的功能:var a = (5).plus(3).minus(6);

    Number.prototype.plus= function(val){ return parseInt(this)+val; }; Number.prototype.minus= function ...

  2. iOS操作系统的层次结构

    iOS操作系统4层结构,如下表 可触摸层 Cocoa Touch layer 媒体层 Media layer 核心服务层 Core Services layer 核心操作系统层 Core OS lay ...

  3. 自定义可伸缩的imageView

    直接上代码 /** * 自定义可伸缩的ImageView */ public class ZoomImageView extends ImageView { /** 画笔类 **/ private P ...

  4. window.close() 关闭当前浏览器页

    function eseFun() { var browserName = navigator.appName; //获取浏览器名称 if(browserName == "Netscape& ...

  5. UIButton zoomin pressed

    // Scale up on button press - (void) buttonPress:(UIButton*)button { button.transform = CGAffineTran ...

  6. 成魔笔记1——先入IT,再成魔

    关于我为什么要写这个博客的原因,做一个简单的解释.因为报考的一时兴起,我选择了软件专业.可是三年下来,感觉自己没做多少事,也没收获到多少东西.很多时候都是老师讲什么,都是完全陌生的东西,跟不上教学的思 ...

  7. 如何启动Intel VT-x

    如何启动Intel VT-x 5 在64bit win7系统下安装了Vmware10,然后安装64位的UbuntuKylin 14.04,想要打开UbuntuKylin,弹出如下对话框: 请问该如何启 ...

  8. The - Modcrab——使用贪心策略

    一.题目信息 The - Modcrab 简单翻译一下:Vova有生命值h1,每次攻击值为a1,每瓶药水恢复生命值c1;Modcrab有生命值h2,每次攻击值为a2.在每个关卡开始,Vova有两种选择 ...

  9. v-if与v-show的区别与选择

      v-if与v-show的区别与选择 官网给的区别 v-if 是“真正”的条件渲染,因为它会确保在切换过程中条件块内的事件监听器和子组件适当地被销毁和重建. v-if也是惰性的:如果在初始渲染时条件 ...

  10. 数据库:SQL Server自增长列的编号

    SQL Server表中的自动编号ID重新开始排列 说法一: 有两种方法: 方法1: truncate table 你的表名 --这样不但将数据删除,而且可以重新置位identity属性的字段. 方法 ...