TOJ 2446: Mint
2446: Mint 
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的更多相关文章
- 种类并查集,TOJ(1706)
题目链接:http://acm.tju.edu.cn/toj/showp1706.html 很类似Poj的一道帮派的问题,记得找到的可疑的关系,不要将集合刷新就可以了. 1706. A Bug's ...
- 在Linux Mint上安装node.js和npm
1.安装Node.js 前端开发过程中,很多项目使用npm的http-server的模块来运行一个静态的服务器,我个人在Dell的笔记本上安装的是Linux Mint最新版本,所以想尝试一下在Linu ...
- 在Ubuntu和Linux Mint上安装Oracle JDK
在Ubuntu和Linux Mint上安装Oracle JDK 使用下面的命令安装,只需一些时间,它就会下载许多的文件,所及你要确保你的网络环境良好: sudo add-apt-repository ...
- Mint linux 自定义上下文菜单实现ZIP压缩文件无乱码解压
1. 前提条件 我的Mint Linux 是Thunar文件管理器(默认的). 2. 配置自定义动作 打开Thunar文件管理器,点击菜单“编辑”=>“配置自定义动作”.点击“+”添加一个新的. ...
- 解决:Win 10 + Mint 18双系统时间不同步,更换系统启动项顺序
1.win10 & mint 18双系统时间同步: 先打开终端下更新一下时间,确保时间无误: sudo apt-get install ntpdate sudo ntpdate time.wi ...
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- 安装Linux Mint
1.尽量选择trusty的安装版本,kde和xfce不支持Win+..快捷键,推荐cinnamon:制作安装U盘后,选择非EFI模式启动:选择start Linux Mint(就是第一项): 2.In ...
- Linux Mint 17使用小结
用过蛮多的linux系统 linux mint是我比较喜欢和常用的一个系统,装的是linux mint xfce 64位版本,在这里记录使用中遇到的一些问题及解决的方法,备忘,方便以后查看. 1.首先 ...
- Linux mint 18版本开启SSH服务
linux mint 18版本默认是没有安装ssh server的 需要手动安装 安装ssh server: 此命令需要联网,会自动下载安装 安装之后看是否开始了ssh, 看到ssh-agent 和s ...
随机推荐
- I/O————数据流
如何将一个long类型的数据写入文件中? 转字符串 → 通过 getbytes() 写进去,费劲,而且在此过程中 long 类型的数需要不断地转换. 现在,Java 中的数据流能够很好的解决这个问题( ...
- Linux用户管理-用户账号管理
一.用户账号的增.删.改.查 1>添加用户------useradd 注:1.用户名不应是纯数字或者以数字开头 2.将登陆shell改为/sbin/nologin可禁止用户登录 格式:usera ...
- react中的context的基础用法
context提供了一种数据共享的机制,里面有两个关键概念——provider,consumer,下面做一些key features描述. 参考网址:https://react.docschina.o ...
- nl
-b -b -a 表示不论是否为空行,也同样列出行号 -b -t 如果用空行,空行不要列出行号 -n 列出行号表示方法,主要有3中 -n -n ln 行号显示在屏幕的最左方显示 -n rn 行号显示在 ...
- [Ubuntu]清除系统磁盘垃圾
操作步骤: 1.sudo apt-get autoremove(卸载系统中所有未被使用的依赖关系) 2.sudo apt-get clean(清除所有缓存的包文件) 以上操作绿色无害,对系统无影响.
- Azure资源管理工具Azure PowerShell介绍
什么是 Azure PowerShell? Azure PowerShell 是一组模块,提供用于通过 Windows PowerShell 管理 Azure 的 cmdlet.你可以使用 cmdle ...
- 包含日志文件getshell
包含日志文件getshell 一.包含日志文件漏洞利用概述 当我们没有上传点,并且也没有url_allow_include功能时,我们就可以考虑包含服务器的日志文件. ...
- Scala 的list
9.1 使用列表 列表类型:跟数组一样,列表也是同质化的(homogeneous).即所有元素都要是同种类型. 列表结构:所有列表由两部分组成:Nil 和 ::(cons). 基本操作:主要有三个:h ...
- java 读取文件转换成字符串
public String readFromFile(File src) { try { BufferedReader bufferedReader = new BufferedReader(new ...
- Core Foundation 框架
Core Foundation框架 (CoreFoundation.framework) 是一组C语言接口,它们为iOS应用程序提供基本数据管理和服务功能.下面列举该框架支持进行管理的数据以及可提供的 ...