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 ...
随机推荐
- sqlite3-入门教程
*** 非常好 http://wenku.baidu.com/link?url=xDoS4prJaGRac0QS0nxdNr6056N-qJIfZ7OhiTharj1ntuIsNy9sWXWvBXLh ...
- React Native学习(八)—— 对接七鱼客服
本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...
- 进程间通信之利用CreateFilemapping()
这两天在复习进程间通信,复习一下记不住,复习一下记不住...就写个小博客献个丑,先来第一个内存映射 代码亲测通过 CreateFileMapping()的最后的一位用来做进程间通信 步骤: 1.Cre ...
- bxslider使用教程
bxSlider下载+参数说明 "bxSlider"就是一款响应式的幻灯片js插件 bxSlider特性 充分响应各种设备,适应各种屏幕: 支持多种滑动模式,水平.垂直以及淡入淡出 ...
- yum错误,Cannot find a valid baseurl for repo: base 和 No more mirrors to try
可能出错原因: 1. yum 配置错误 2. 虚拟机无法连接外网 3. 域名解析没有 如何解决这个错误? 1. 网上找 /ect/yum.conf 和 /etc/yum.repos.d/CentOS- ...
- vm虚拟机中linux无法连接外网?
问题出现的环境? vm虚拟机中安装了linux系统,vm设置了NAT方式共享主机ip,但还是没法访问外网?在linux系统中查询ip地址,没有ipv4地址,就是配置了自动获取,但是还是没有获取? 问题 ...
- python_10_文件操作
文件操作逻辑? 打开文件,赋值给一个对象 用对象操作文件 关闭文件 如何打开文件? 在windows中,默认格式gbk,python3.x默认unicode(utf-8),要指定编码值 语法: f = ...
- 重温吕鑫MFC教学视频(一)
重温吕鑫MFC教学视频(一)1. picture控件的使用,可以显示icon和bitmap2. WM_Create窗口的创建3. 创建的销毁消息及区别WM_SYSCOMMAND WM_CLOSE WM ...
- Linux指令--head,tail
原文出处:http://www.cnblogs.com/peida/archive/2012/11/06/2756278.html head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头 ...
- Servlet--传参和接参
OK,现在基本的Servlet接口和常用类都整理的差不多的,本篇博客开始整理Servlet和页面的交互. 1,接参 以下几个常用的方法: getParameter public String getP ...