此题之水,水于上青天

$(1<=n<=100,0<=d<=1001<=n<=100,0<=d<=100 )$

$n$ 只有100!

思路:

sort排序,再双重循环枚举,求出范围 $i$ ~ $j$ ,其余剩下的(不在这个范围内的),比如 $a[i-1]$ ,就是删去的。然后打擂台:

m=min(m,n-j+i-1);//算出i~j里面有多少个数字

最后输出m即可。

AC CODE:

#include<iostream>
#include<algorithm>//sort头文件
using namespace std;
int n,m=100000000;//m一定要开大一点!
int d;
int a[30000];
int main(){cin>>n>>d;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+n+1);//排序for(int i=1;i<=n;i++){for(int j=i;j<=n;j++){//可能存在i=j(最大值和最小值相同的情况)if(a[j]-a[i]<=d){m=min(m,n-j+i-1);//打擂台}}}cout<<m;return 0;//华丽的结束
}

码风新奇勿喷

题解 CF940A 【Points on the line】相关推荐

  1. LeetCode: Max Points on a Line

    LeetCode: Max Points on a Line LeetCode: Max Points on a Line Given n points on a 2D plane, find the ...

  2. 北邮OJ 85. Three Points On A Line

    85. Three Points On A Line 时间限制1000 ms    内存限制 65536 KB     题目描述 Given points on a 2D plane, judge w ...

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

  4. 【重要+细节】LeetCode 149. Max Points on a Line

    LeetCode 149. Max Points on a Line Solution1: 参考花花酱:https://zxi.mytechroad.com/blog/geometry/leetcod ...

  5. [LeetCode] Max Points on a Line 题解

    题意 Given n points on a 2D plane, find the maximum number of points that lie on the same straight lin ...

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

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

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

  9. leetcode 149. Max Points on a Line |149. 直线上最多的点数(Java)

    题目 https://leetcode.com/problems/max-points-on-a-line/ 题解 hard 题,普通解法不难,有几个小坑: key : key : value 的存储 ...

最新文章

  1. tensorflow inceptionv3参数笔记
  2. spring cloud API网关
  3. Jmeter学习系列----1 环境搭建
  4. 深度学习的数学 (5)偏导数
  5. 深入理解计算机操作系统(一)
  6. linux代码段映射,bss,data,text,rodata,堆,栈,常量段与其各段在物理存储中关系
  7. CCF202112-1 序列查询
  8. win11在dev渠道升级怎么保留原来的文件 windows11渠道升级保留原文件的方法步骤
  9. php 卷积神经网络,PyTorch上实现卷积神经网络CNN的方法
  10. jq 遍历map集合
  11. 谷歌发布研究人口流动性的新方法【智能快讯】
  12. python怎么设置随机数种子_Pytorch在dataloader类中设置shuffle的随机数种子方式
  13. 机器学习是什么?详解机器学习概念
  14. [PC] 微软账号连接不上
  15. Eclipse中文语言包下载后怎么使用
  16. Spring Boot安装及使用(2021.10.28)
  17. 三位水仙花数 Python
  18. 2021考生如何做考博英语复习规划?
  19. bin文件和hex文件互转
  20. 使用VB.net将PNG图片转成icon类型图标文件

热门文章

  1. 【面试利器】 原生JS灵魂拷问,你能答上多少(一)
  2. Python基础1——读取数据(公众号数据科学实践)
  3. CLA not signed yet
  4. 1-18 Collections工具类和StreamAPI流式编程
  5. matlab画三维点坐标,已知各个点的三维坐标(x,y,z),怎么用MATLAB画三维图
  6. 我的世界服务器宝石系统,我的世界1.9-1.7宝石镶嵌插件
  7. 网络摄像头Androi端显示(mjpeg)源码分析
  8. Unity游戏开发工具的下载与安装
  9. svn没有绿色的对勾处理
  10. 第十九讲 信息安全管理【2021年软考-高级信息系统项目管理师】