CF940A Points on the line 思维
1 second
256 megabytes
standard input
standard output
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.
Diameter of multiset consisting of one point is 0.
You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?
The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively.
The second line contains n space separated integers (1 ≤ xi ≤ 100) — the coordinates of the points.
Output a single integer — the minimum number of points you have to remove.
3 1
2 1 4
1
3 0
7 7 7
0
6 3
1 3 4 6 9 10
3
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3,4 and 6, so the diameter will be equal to 6 - 3 = 3.
要求去除多少个数剩下的才满足条件,我们转化成求满足条件的个数,总数减去满足条件的个数就是要去除的个数。
#include<map>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 100010
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
int main() {
int n,m;
while( cin >> n >> m ) {
int a[];
for( int i = ; i < n; i ++ ) {
cin >> a[i];
}
sort( a, a + n );
int num = ;
for( int i = ; i < n; i ++ ) {
for( int j = i; j < n; j ++ ) {
if( a[j] - a[i] <= m ) {
num = max( num, j - i + );
}
}
}
cout << n - num << endl;
}
return ;
}
CF940A Points on the line 思维的更多相关文章
- Codeforces Round #466 (Div. 2) -A. Points on the line
2018-02-25 http://codeforces.com/contest/940/problem/A A. Points on the line time limit per test 1 s ...
- 【leetcode】Max Points on a Line
Max Points on a Line 题目描述: Given n points on a 2D plane, find the maximum number of points that lie ...
- [LeetCode OJ] Max Points on a Line
Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...
- [leetcode]149. Max Points on a Line多点共线
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- LeetCode:149_Max Points on a line | 寻找一条直线上最多点的数量 | Hard
题目:Max Points on a line Given n points on a 2D plane, find the maximum number of points that lie on ...
- [LintCode] Max Points on a Line 共线点个数
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- Max Points on a Line leetcode java
题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight li ...
- 【LeetCode】149. Max Points on a Line
Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the ...
- LeetCode: Max Points on a Line 解题报告
Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the ...
随机推荐
- 章节十五、5-记录日志---Log4j
一.为什么要用Log4j记录日志? 日志记录对于任何应用程序都非常重要. 它可以帮助我们快速调试代码,通过收集代码执行的信息让代码容易维护. 二.Log4j 是什么? Apache为Java提供的日志 ...
- Socket编程:UDP和TCP概论及案例
网络编程的三要素: 1.IP地址 2.端口 3.协议 什么是Socket? Socket就是通信链路的端点称"套接词". 基于TCP协议的Socket网络通信: 用来实现双向安全 ...
- golang const 内itoa 用法详解及优劣分析
首先itoa 是什么 const 内的 iota是golang语言的常量计数器,只能在常量的表达式中使用,,即const内. iota在const关键字出现时将被重置为0(const内部的第一行之前) ...
- 手动编译PHP开发环境
目录 手动编译PHP开发环境 问题复盘 部署环境及配置 目标环境 安装部署环境开始 首先安装PHP 安装mysql 安装nginx 手动编译PHP开发环境 这是一篇来自深夜加班的手稿 问题复盘 你有没 ...
- 逆向破解之160个CrackMe —— 002-003
CrackMe —— 002 160 CrackMe 是比较适合新手学习逆向破解的CrackMe的一个集合一共160个待逆向破解的程序 CrackMe:它们都是一些公开给别人尝试破解的小程序,制作 c ...
- Linux lsof工具介绍
引言 在<Linux fuser工具介绍>一文中,与大家一起学习了fuser工具的使用方法."lsof"——list open files,lsof也是Linux下用于 ...
- (2019版本可用)【idea的安装,激活,设置,卸载】
前言 也差不多也可以使用简单快捷的idea软件了,相对于elicpse而言的话,idea是非常好用的,虽然现在涉及不是很广. 什么是idea? IDEA 全称IntelliJ IDEA,是用于java ...
- Flink 源码解析 —— Flink JobManager 有什么作用?
JobManager 的作用 https://t.zsxq.com/2VRrbuf 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1学习 -- Mac ...
- Flink 源码解析 —— JobManager 处理 SubmitJob 的过程
JobManager 处理 SubmitJob https://t.zsxq.com/3JQJMzZ 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1 ...
- (三)c#Winform自定义控件-有图标的按钮
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...