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. (一)MySQL基础篇

    1.mysql简介 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库. 主流的数据库有:sqlserver,mysql,Oracle.SQLite.Access.MS SQL Se ...

  2. 【Nginx】nginx为目录或网站加上密码认证

    第一步生成pwd用户名密码文件 工具:http://trac.edgewall.org/export/10770/trunk/contrib/htpasswd.py 步骤: chmod 777 htp ...

  3. laravel5.6 调用第三方类库

    大概流程: 1. 新建一个目录方类库 2. 配置composer配置文件 3. 在项目中使用终端运行composer  dumpautoload 4. 使用时 方法调用可以new对象后->方法名 ...

  4. 【设计模式】C++中的单例模式

    讲解来自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&id=4281275&uid=26611383 由于使用了POSIX函 ...

  5. 【Python】python操作mysql

    pymysql模块对mysql进行 import pymysql # 创建连接 conn = pymysql.connect(host=, user='root', passwd='root', db ...

  6. HDU——1573 X问题

    又来一发水题. 解同余方程而已,用类似于剩余定理的方法就O了. 直接上代码:(注意要判断是否有解这种情况) #include <iostream> #include <cstdio& ...

  7. 创建 cachingConfiguration 的配置节处理程序时出错: 未能加载文件或

    C:\Users\xxx\Documents\IISExpress\config\applicationhost.config 将这里面带的项目路径替换成你当前路径 {"创建 caching ...

  8. Codeforces 576D. Flights for Regular Customers(倍增floyd+bitset)

    这破题调了我一天...错了一大堆细节T T 首先显然可以将边权先排序,然后逐个加进图中. 加进图后,倍增跑跑看能不能到达n,不能的话加新的边继续跑. 倍增的时候要预处理出h[i]表示转移矩阵的2^0~ ...

  9. Codeforces 576C. Points on Plane(构造)

    将点先按x轴排序,把矩形竖着划分成$10^3$个块,每个块内点按y轴排序,然后蛇形走位上去. 这样一个点到下一个点的横坐标最多跨越$10^3$,一共$10^6$个点,总共$10^9$,一个块内最多走$ ...

  10. [HEOI2014]逻辑翻译

    ywy_c_asm的良心题解 是道好题 体现了二进制位的形象递归思想,以及将FWT的思路(都是拆位分治)用到题目中的典范 可以暴力高斯消元.完全没有利用2^N以及+-1的良好性质 发现项数,方程和二进 ...