根据抽屉原理显然m>=(n-K) 于是在[n-K,max(a1..an)+1]的范围中枚举m 考虑K=0的做法... 如果a[i]≡a[j](mod m),则有m|(a[i]-a[j]),只要O(n²)记录下所有a[i]-a[j],找在max范围内m的倍数是否出现过就行了.根据调和级数复杂度为O(n²+max log max) 如果K>0 我们记录下m的倍数出现过的次数cnt,如果cnt>k*(k+1)/2说明至少有k+1个数模m同余,显然不可行 如果满足cnt<=k*(k+1)/…
N个不同的数a[1],a[2]...a[n],你可以从中去掉K个数,并且找到一个正整数M,使得剩下的N - K个数,Mod M的结果各不相同,求M的最小值. Input 第1行:2个数N, K,中间用空格分隔,N表示元素的数量,K为可以移除的数的数量(1 <= N <= 5000, 0 <= K <= 4, 1 <= a[i] <= 1000000). Output 输出符合条件的最小的M. Input示例 5 1 1 2 10 11 12 Output示例 4————…
You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the minimum modular m (m > 0), so that for every pair of the remaining integers (ai, aj), the following unequality holds: . Input The first line contains…
Minimum Modular time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the minimum modular m (m > 0…
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:http://blog.csdn.net/u014357885/article/details/46044287 */ #include <cstdio> #include <algorithm> #include <cstring> #include <iostream…
题目连接:uva 10560 - Minimum Weight 题目大意:给出n,问说至少须要多少个不同重量的砝码才干称量1~n德重量,给出所选的砝码重量,而且给出k,表示有k个重量须要用上述所选的砝码測量. 解题思路:重量为1的砝码肯定要选,它能够表示到1的重量,那么下一个砝码的重量肯定选择3(2∗1+1),这样1,3分别能够用一个砝码表示,而2,4分别为3-1和3+1,这样1~4的重量也都能够表示.于是有公式ai=si−1∗2+1. #include <cstdio> #include &…
题目: Description standard input/outputStatements Given an integer n, find out number of ways to represent it as the sum of two or more integers ai with the next property: ratio ai / ai - 1is the same positive integer for all possible i > 1. Input Inpu…
题意是现在有n个雕像把一个圆等分了,每一个雕像有一个吸引力. 叫你不移动雕像只去掉雕像让剩下的雕像还能等分这个圆,求剩下的雕像的吸引力之和的最大值. 显然去掉后剩下雕像的间隔应该是n的因子,因为这样才能使剩下的雕像等分圆. 这道题数据量不大,可以暴力枚举,模拟出每一种情况取最大值就可以了. 现在我们分析完这道题了,写一下步骤. 1.求出n的因子存在list中. ;i <= n/; i++) l.push_back(i); } 2.遍历因子(因子是可以去取的间隔),遍历从1到因子作为第一个取的雕像…
51nod 1483 化学变换 题面 给出n个整数(n <= 1e5,每个数 <= 1e5),对每个数都可以进行多次操作,操作有两种:乘二/整除以二. 问最少经过多少次操作能使所有数相等. 题解 对于每个数,枚举它变成另外一个数(目标数)所需的最小步数,目标数的代价值 += 这个最小步数.这样最后输出所有目标数中代价值最小的即可. 注意,对于一个奇数,把它除以二之后再乘以二,得到的是一个新数. #include <cstdio> #include <cmath> #in…
题面 有一个a数组,里面有n个整数.现在要从中找到两个数字(可以是同一个) ai,aj ,使得 ai mod aj 最大并且 ai ≥ aj. Input 单组测试数据. 第一行包含一个整数n,表示数组a的大小.(1 ≤ n ≤ 2*10^5) 第二行有n个用空格分开的整数ai (1 ≤ ai ≤ 10^6). Output 输出一个整数代表最大的mod值. Input示例 3 3 4 5 Output示例 2 对每个数,枚举它的所有倍数,找到比这个倍数小并且最接近这个倍数的数,更新ans. 是…