传送门

题目大意

给你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的更多相关文章

  1. 【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 ...

  2. [LeetCode OJ] Max Points on a Line

    Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...

  3. [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. ...

  4. 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 ...

  5. 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 ...

  6. [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. ...

  7. 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 ...

  8. 【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 ...

  9. 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 ...

随机推荐

  1. Phpstorm10 主题下载

    ================================================================================ submit:主题 http://ww ...

  2. CCF系列之最优灌溉(201412-4)

    试题编号:201412-4试题名称:最优灌溉时间限制: 1.0s内存限制: 256.0MB 问题描述 雷雷承包了很多片麦田,为了灌溉这些麦田,雷雷在第一个麦田挖了一口很深的水井,所有的麦田都从这口井来 ...

  3. P1251 餐巾计划问题

    P1251 餐巾计划问题 题目描述 一个餐厅在相继的 N 天里,每天需用的餐巾数不尽相同.假设第 iii 天需要 rir_iri​块餐巾( i=1,2,...,N).餐厅可以购买新的餐巾,每块餐巾的费 ...

  4. Java线程-异常处理

    在Java多线程程序中,所有线程都不允许抛出未捕获的checked exception,也就是说各个线程需要自己把自己的checked exception处理掉.这一点是通过java.lang.Run ...

  5. apktool给软件加注册机修改图标和文件名

    功能实现,即让你的软件具有注册机功能,或者破解别人的软件,据为己有! 先反编译文件包 然后全局工具,修改图标和名称 加注册机,输入key,下载计算器,即可.给某个用户设置自定义的使用时间!

  6. Python中变量和常量的理解

    一.变量的定义:把程序运算的中间结果临时存到内存里,以备后面的代码继续调用,这几个名字的学名就叫做"变量". 二.变量的作用:变量用于存储要在计算机程序中引用和操作的信息.它提供了 ...

  7. 通过编程为Outlook 2007添加邮件规则

    Outlook 所支持的邮件规则相当有用,我们经常需要针对某些特征的邮件做特殊的处理.例如将其移动到某个特定文件夹,或者删除它等等. Outlook所支持的邮件规则主要两大类:收到邮件时和发送邮件时 ...

  8. Nagios学习实践系列

    其实上篇Nagios学习实践系列--基本安装篇只是安装了Nagios基本组件,虽然能够打开主页,但是如果不配置相关配置文件文件,那么左边菜单很多页面都打不开,相当于只是一个空壳子.接下来,我们来学习研 ...

  9. 汉诺塔python3函数编写和过程分析

    !/usr/bin/env python3 -- coding: utf-8 -- 利用递归函数计算阶乘 N! = 1 * 2 * 3 * ... * N def fact(n): if n == 1 ...

  10. C# 类型基础(上)

    C#类型都派生自System.Object 祖先的优良传统:Object的公共方法 Equals: 对象的同一性而非相等性 GetHashCode:返回对象的值的哈希码 ToString:默认返回类型 ...