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 ...
随机推荐
- 访问者模式和php实现
访问者模式: 表示作用于某个对象结构中的各个元素的操作.它使你可以在不改变各个元素类的前提下定义作用于这些元素的操作. 角色: 1)抽象访问者:为该对象结构中具体元素角色声明一个访问操作接口.该操作接 ...
- cf559C. Gerald and Giant Chess(容斥原理)
题意 $h \times w$的网格,有$n$个障碍点, 每次可以向右或向下移动 求从$(1, 1)$到$(h, w)$不经过障碍点的方案数 Sol 容斥原理 从$(1, 1)$到$(h, w)$不经 ...
- mybatis实现使用原生的sql
1.相应的xml文件中 <select id="selectByCategories" resultType="map" parameterType=&q ...
- Android 两个ArrayList找出相同元素及单个ArrayList删除元素
//从一个ArrayList中删除重复元素 List<String> arrayList1 = new ArrayList<String>(); arrayList1.add( ...
- RunTests.sh && RunIPhoneSecurityd.sh
https://github.com/gh-unit/gh-unit/blob/master/Scripts/RunTests.sh #!/bin/sh # If we aren't ru ...
- 各种分布(distribution)
正态分布(Normal distribution),又名高斯分布(Gaussian distribution).若随机变量X服从一个数学期望为μ.方差为σ^2(标准差为σ)的正态分布,记为N(μ,σ^ ...
- linux_1
注: 创建软连接: "ln -s xxx 路径1" 在路径1创建xxx的软连接 特点: 1.文件类型 l 2.相当于windows的快捷方式 创建硬链接: "ln xxx ...
- Arch Linux 天坑
https://wiki.archlinux.org/index.php/Samba_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) samba gui客户端 smb4 ...
- js最高效的数组去重方法
var arr=[1,2,33,2,4,5,33,5,7,8,1,3];var result=[];var temp={};for( var i=0;i<arr.length;i++){ if( ...
- 单机简单搭建一个kafka集群(没有进行内核参数和JVM的调优)
1.JDK安装 在我的部署单节点kafka的博客里有相关的方法.(https://www.cnblogs.com/ToBeExpert/p/9789486.html )zookeeper和kafka的 ...