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 ...
随机推荐
- Red Hat
同义词 REDHAT一般指Red Hat Red Hat(红帽)公司(NYSE:RHT)是一家开源解决方案供应商,也是标准普尔500指数成员.总部位于美国北卡罗来纳州的罗利市,截止2015年3月3日, ...
- dede后台出现 保存目录数据时失败,请检查你的输入资料是否存在问题
dede 5.7无法增加顶级/二级栏目,保存目录数据时失败,请检查你的输入资料是否存在问题!执行了SQL还是不行 解决档案:用正常可以添加栏目的,将E:\wamp\www\dededln\back(d ...
- TP5 中实现支付宝支付 利用model层调用支付宝类库
<?php /** * Created by PhpStorm. * User: admin * Date: 2017/8/16 * Time: 09:16 */ namespace app\a ...
- 语句、变量等js最基本知识
JavaScript的最为基本知识 1语法 js是区分大小写的:标识符就是指变量.函数.属性的名字或者是参数,标识符可以是字母,下划线,美元符号,数字,注意第一个不能是数字:js采用的是驼峰大小格式: ...
- 数据库复习总结(6)-SQL语句入门(脚本、命令)
脚本操作: 脚本操作 注释:--单行注释,/**/多行注释 数据库:创建.删除 (可以通过查看master数据库中的sysdatabase表,来了解当前存在的数据库) 点击“新建查询”,选中哪句执行哪 ...
- [one day one question] webpack打包压缩 ES6 js、.vue报错
问题描述: 报错: ERROR in js/test.js from UglifyJs Unexpected token punc ?(?, expected punc ?:? [js/test.js ...
- .net Core连接MongoDB
前两天在学习MongoDB相关的知识,做了个小Demo,大概是省份里面有多少所学校 连接MongoDB首先要通过Nuget添加一个MongoDB的包,下载此包 安装完毕后开始写代码了,创建一个省份实体 ...
- 二、Html基本语法
1,XHTML的基本结构和规则 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < ...
- 查阅API文档
Java的API文档:就一句话:应用程序接口 •API (Application Programming Interface,应用程序编程接口)是 Java 提供的基本编程接口. •Java语言提供了 ...
- 通过反编译深入理解Java String及intern(转)
通过反编译深入理解Java String及intern 原文传送门:http://www.cnblogs.com/paddix/p/5326863.html 一.字符串问题 字符串在我们平时的编码工作 ...