51nod 1217 Minimum Modular
第1行:2个数N, K,中间用空格分隔,N表示元素的数量,K为可以移除的数的数量(1 <= N <= 5000, 0 <= K <= 4, 1 <= a[i] <= 1000000)。
输出符合条件的最小的M。
5 1
1
2
10
11
12
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的更多相关文章
- 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 ...
- codeforces 303C. Minimum Modular(数论+暴力+剪枝+贪心)
You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the ...
- CF 303C——Minimum Modular——————【剪枝】
Minimum Modular time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 【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 ...
- NOIP2018提高组金牌训练营——数论专题
地址 https://www.51nod.com/live/liveDescription.html#!liveId=23 1187 寻找分数 给出 a,b,c,d, 找一个分数p/q,使得a/b & ...
- codeforce303C-Minimum Modular-剪枝,暴力
Minimum Modular 题意:就是在一堆数字中,每一个数字对m取模不能等于这堆数字中的其他数字,同时给了K个机会可以删除一些数字.求最小的m: 思路:我一开始完全没思路,队长说的并查集什么的不 ...
- Codeforces Round #183 (Div. 2)
A. Pythagorean Theorem II 暴力,\(O(n^2)\). B. Calendar 每个日期计算到0年1月1日的天数,相当于转化成前缀和形式. 闰年数计算\[\lfloor\fr ...
- 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 ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
随机推荐
- spring框架(3)— spring集合类的注入
1.Car.java package com.eniac.beans; public class Car { private String type; private String factory; ...
- JS 中substring() , substr(), slice() 的区别
substr(start, length) : 截取从start索引开始的字符,长度为length的字符串 substring(start, end) : 截取从start索引开始的字符,以end索引 ...
- Windows下IntelliJ IDEA中调试Spark Standalone
参考:http://dataknocker.github.io/2014/11/12/idea%E4%B8%8Adebug-spark-standalone/ 转载请注明来自:http://www.c ...
- [mysqld_safe]centos7 mysql 安装与配置
查资料发现是CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了. 有两种解决办法: 安装mariadb [root@a ~]# yum install mar ...
- 使用TestNG 和 CSV文件进行数据驱动
package testNGPractice; import java.io.BufferedReader; import java.io.FileInputStream; import java.i ...
- PHP关于传众多参数还是传上下文对象的性能测试
在开发微信公众平台平台的过程中,有这么几个参数总是需要传来传去,$userOpenId,$message,$time. 在整个程序的运行过程中,为了函数方便的处理,将这三个变量一直放在参数列表里.关于 ...
- 利用vs10和opencv识别图片类型身份证的号码
遇到的问题: 1 持续灰色图像框 waitkey()要在imshow()之前调用. 2 CvRect 和Rect CvXXX是C语言的接口,cv::XXX是C++语言的接口.两者混在一起容易出错 3 ...
- 解决Qt creator无法输入中文
详细的方法来自以下网址: http://my.oschina.net/lieefu/blog/505363?p={{currentPage+1}} 需要说明的几点: 设置qmake 的路径使用自身的路 ...
- [讲解]sql except和intersect运算符(比拟两个或多个select语句的结果并前去非重复值)
图 1 UNION 中若有重复的行,会被移除,只留下一个 1.简介 EXCEPT和INTERSECT运算符使您可以比较两个或多个SELECT语句的结果并返回非重复值. 2.区别 EXCEPT运算符返回 ...
- 第181天:HTML5——视频、音频
一.HTML5新增的video.source标签 <video width="320" height="240" controls="contr ...