940A Points on the line
题目大意
给你n和d还有n个数,计算最少删除几个点可以是最大点与最小点之差小于等于d
分析
先对所有点排序,枚举每一个点ai到ai+d中有几个点,答案即n-其中最大的值
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int a[500];
int is[500];
int main()
{ int n,d,i,j,k,ans=0;;
cin>>n>>d;
for(i=1;i<=n;i++){
cin>>a[i];
is[a[i]]++;
}
sort(a+1,a+n+1);
for(i=1;i<=n;i++){
int sum=0;
for(j=0;j<=d;j++)
if(is[a[i]+j])sum+=is[a[i]+j];
ans=max(sum,ans);
}
cout<<n-ans<<endl;
return 0;
}
940A Points on the line的更多相关文章
- 【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. ...
- 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: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 ...
随机推荐
- 转载]浅析DEDECMS织梦留言板调用网站head.htm以及自定义的方法
原文地址:浅析DEDECMS织梦留言板调用网站head.htm以及自定义的方法作者:it_wang 今天,一个客户朋友问到织梦留言板如何调用head.htm以及自定义,企业网站源码之前有摸索过,但是没 ...
- sqlite数据库的char,varchar,text,nchar,nvarchar,ntext的区别
1.CHAR.CHAR存储定长数据很方便,CHAR字段上的索引效率级高,比如定义char(10),那么不论你存储的数据是否达到了10个字节,都要占去10个字节的空间,不足的自动用空格填充. 2.VAR ...
- POI--HSSFCellStyle类
通过POI来进行单元格格式的设定 设定格式使用「HSSFCellStyle」类.它有一个构造方法: protected HSSFCellStyle(short index, ExtendedForma ...
- 【javaweb学习笔记】WEB01_HTML
案例一:网站信息显示页面1.什么是HTML?(Hyper Text Markup Language:超文本标记语言) 超文本:功能比普通文本更加强大 标记语言:使用一组标签对内容进行描述的一门语言(它 ...
- 面试必问的 volatile,你了解多少?
前言 Java中volatile这个热门的关键字,在面试中经常会被提及,在各种技术交流群中也经常被讨论,但似乎讨论不出一个完美的结果,带着种种疑惑,准备从JVM.C++.汇编的角度重新梳理一遍. vo ...
- java 网络编程之TCP通信和简单的文件上传功能
*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...
- strlen出错
1.特别奇怪的错误 $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= ...
- matlab文件读写处理实例(三)——读取文件特定行
(1) 读取文件特定行 CODE: ; ; if nline==line fprintf(fidout,'%s\n',tline); data ...
- 最全 Linux 磁盘管理基础知识全汇总
一.存储设备的挂载和卸载 存储设备的挂载和卸载常用操作命令:fdisk -l.df.du.mount.umount. fdisk -l 命令 1.作用 查看所有硬盘的分区信息,包括没有挂上的分区和 ...
- 基于 HTML5 WebGL 的 3D SCADA 主站系统
这个例子的初衷是模拟服务器与客户端的通信,我把整个需求简化变成了今天的这个例子.3D 的模拟一般需要鹰眼来辅助的,这样找产品以及整个空间的概括会比较明确,在这个例子中我也加了,这篇文章就算是我对这次项 ...