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
————————————————————————
如果a%mod==b%mod 那么(a-b)%mod==0
所以我们可以枚举mod 然后一波剪枝水过QAQ
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=1e5+,N=;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int n,k,mx,v[M],vis[N],f[N];
int main()
{
n=read(); k=read();
if(n+<=k) return puts(""),;
for(int i=;i<=n;i++) v[i]=read(),mx=max(mx,v[i]);
sort(v+,v++n);
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
f[v[j]-v[i]]++;
for(int i=n-k;i<=mx;i++){
int cnt=;
for(int j=;i*j<=mx;j++) cnt+=f[i*j];
if(cnt>(k*(k+)>>)) continue;
cnt=;
for(int j=;j<=n;j++){
int now=v[j]%i;
if(vis[now]!=i) vis[now]=i;
else cnt++;
}
if(cnt<=k) return printf("%d\n",i),;
}
return ;
}
 

51nod 1217 Minimum Modular的更多相关文章

  1. 51nod 1217 Minimum Modular(数论+暴力)

    根据抽屉原理显然m>=(n-K) 于是在[n-K,max(a1..an)+1]的范围中枚举m 考虑K=0的做法... 如果a[i]≡a[j](mod m),则有m|(a[i]-a[j]),只要O ...

  2. codeforces 303C. Minimum Modular(数论+暴力+剪枝+贪心)

    You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the ...

  3. CF 303C——Minimum Modular——————【剪枝】

    Minimum Modular time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. 【leetcode】1217. Minimum Cost to Move Chips to The Same Position

    We have n chips, where the position of the ith chip is position[i]. We need to move all the chips to ...

  5. NOIP2018提高组金牌训练营——数论专题

    地址 https://www.51nod.com/live/liveDescription.html#!liveId=23 1187 寻找分数 给出 a,b,c,d, 找一个分数p/q,使得a/b & ...

  6. codeforce303C-Minimum Modular-剪枝,暴力

    Minimum Modular 题意:就是在一堆数字中,每一个数字对m取模不能等于这堆数字中的其他数字,同时给了K个机会可以删除一些数字.求最小的m: 思路:我一开始完全没思路,队长说的并查集什么的不 ...

  7. Codeforces Round #183 (Div. 2)

    A. Pythagorean Theorem II 暴力,\(O(n^2)\). B. Calendar 每个日期计算到0年1月1日的天数,相当于转化成前缀和形式. 闰年数计算\[\lfloor\fr ...

  8. 4: 模块化应用程序开发 Modular Application Development Using Prism Library 5.0 for WPF (英汉对照版)

    A modular application is an application that is divided into a set of loosely coupled functional uni ...

  9. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

随机推荐

  1. C++ Primer Plus学习:第十一章

    运算符重载 使用方法: 在类的声明中定义重载运算符 datatype operator操作符(datatype); 定义:datatype classname:: operator操作符(dataty ...

  2. Lucene 分词

    在Lucene中很多数据是通过Attribute进行存储的 步骤是同过TokenStrem获取文本信息流 TokenStream stream = a.tokenStream("conten ...

  3. jmeter 安装tps插件

    1.下载  jpgc-graphs-basic-2.0.zip 2.解压并将lib 目录下的 jmeter-plugins-cmn-jmeter-0.4.jar 拷贝到 %JMeter%/lib 目录 ...

  4. HDU3507_Print Article

    这个题目又是一个典型的dp斜率优化的题目.题意是给你n个数,你需要做的是把这个n个数分为连续的若干段,每段的权值为这段数字的和的平方加上M.求最小的总权值. 我们可以根据题意写出朴素版的dp状态转移方 ...

  5. 【刷题】洛谷 P3676 小清新数据结构题

    题目背景 本题时限2s,内存限制256M 题目描述 在很久很久以前,有一棵n个点的树,每个点有一个点权. 现在有q次操作,每次操作是修改一个点的点权或指定一个点,询问以这个点为根时每棵子树点权和的平方 ...

  6. 使当前对象相对于上层DIV 水平、垂直居中定位

    <!doctype html> <html> <head> <meta http-equiv="content-type" content ...

  7. SCWS中文分词,安装说明(以:Win32环境、utf8字符集为例)

    SCWS官方网站:http://www.xunsearch.com/scws/ 1. 根据您当前用的 PHP 版本,下载相应已编译好的 php_scws.dll 扩展库.    目前支持 PHP-5. ...

  8. bzoj4144【AMPPZ2014】Petrol

    题解:  首先注意到起点和终点都是加油站;          假设中途经过某个非加油站的点u,u连到v,离u最近的加油站是x,那么从u到x加油后回到u,再到v一定不比直接从u到v差:        因 ...

  9. 04-树5. File Transfer--并查集

    对于一个集合常见的操作有:判断一个元素是否属于一个集合:合并两个集合等等.而并查集是处理一些不相交集合(Disjoint Sets)的合并及查询问题的有利工具. 并查集是利用树结构实现的.一个集合用一 ...

  10. [POI2014] KUR-Couriers (主席树)

    [POI2014]KUR-Couriers 题目描述 Byteasar works for the BAJ company, which sells computer games. The BAJ c ...