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. BundleConfig包含js,css失败

    今天在做mvc项目的时候,引入了bootstrap样式.但是包含css和js的时候出错了 于是我查阅资料,好多人都说后缀名前面不能包含".",于是我把min前面的".&q ...

  2. Java中的变量——通过示例学习Java编程(4)

    作者:CHAITANYA SINGH 来源:https://www.koofun.com/pro/kfpostsdetail?kfpostsid=14&cid= 变量是用来存放可以更改的值的容 ...

  3. Java面试:投行的15个多线程和并发面试题(转)

    多线程和并发问题已成为各种 Java 面试中必不可少的一部分.如果你准备参加投行的 Java 开发岗位面试,比如巴克莱银行(Barclays).花旗银行(Citibank).摩根史坦利投资公司(Mor ...

  4. Linux KDE 设置显示桌面的快捷键 win+d

    原文链接:http://blog.sina.com.cn/s/blog_4b91893c0100sxxg.html 到KDE下以后发现显示桌面的快捷键被用来显示平铺窗口,在Win下的时候一直用这个快捷 ...

  5. jQuery和AJAX基础

    jQuery和AJAX基础 jQuery 基础: 1.jQuery 选择器: 元素选择器:$("p"): #id 选择器:$("#test"): .class ...

  6. [Tomcat]如何清理缓存

    步骤: 1.进入tomcat文件夹 2.找到work目录 3.work目录下有个catalina目录 4.将catalina目录整个删除

  7. 学习python报错处理

    1.如图所示 原因是因为没有安装火狐浏览器驱动. 解决办法:1.下载火狐浏览器驱动https://github.com/mozilla/geckodriver/releases 2.安装包解压后安装在 ...

  8. vijos 1034 家族(水题日常)

    描述 若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系. 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚.如果x,y是亲戚 ...

  9. Gym 100425A Luggage Distribution (组合数学,二分)

    一开始想着球盒模型,数据范围大,递推会GG. 用凑的方法来算方案.往n个小球之间插两个隔板,方案是(n-1)*(n-2)/2,不区分盒子,三个盒子小球数各不相同的方案数被算了6次(做排列), 两个相同 ...

  10. 结合浅层高层特征的paper总结

    1.ION:在conv3.conv4.conv5和context features上分别进行roi_pooling,在channel那一维进行concat 2.Hypernet:在较浅层max_poo ...