此题之水,水于上青天

$(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. TCP/UDP协议基本概念
  2. SolrQuery的使用
  3. 登录业务介绍(单点登录)
  4. 【BZOJ1857】【SCOI2010】传送带 [三分]
  5. HDOJ2567 ( 寻梦 ) 【切水题,很欢乐~】
  6. linux sql语句传参数,Linux/Unixshell参数传递到SQL脚本
  7. charCodeAt()和charAt()的用法
  8. Linux内核深入理解中断和异常(7):中断下半部:Softirq, Tasklets and Workqueues
  9. MSF+APK注入绕过手机防护上线远控及安全防护建议
  10. ae教程 (四)运动控制 (三)
  11. 大学四年软件工程专业的学习经验总结
  12. 怎么用计算机平方,手机计算器平方怎么按
  13. axios的并发请求和 排队请求
  14. PX30 Android8.1 红外遥控实现
  15. java工程积累——saas之multi-tenancy解析
  16. LiveGBS流媒体平台国标GB/T28181作为下级支持国标级联海康大华宇视华为等第三方国标平台支持对接政务公安内网国标视频平台
  17. linux相关图形与相关命令
  18. 溯源(六)之溯源的方法
  19. Rsync-同步备份服务器脚本
  20. 极简 ssh之 scp

热门文章

  1. 使用jquery获取url及url参数的方法
  2. php5.5.18 32位 php apache2_4.dll,WinXP环境下安装Apache2.2.3 php5.2.0 Mysql5.0.18 phpMyAd
  3. 月入过万的steam搬砖项目教程拆解,看这一篇就够了
  4. Delphi菜单栏背景色-转载收藏学习
  5. Disk Diet for mac (好用的磁盘清理软件)
  6. 计算机考研复试面试常问问题 数据库篇
  7. SAP 账号被锁定,显示无法再进行口令登录的解决办法
  8. 高级计算机维修员+职业资格证书查询,国家职业资格证书查询(全国联网)
  9. 生日祝福html_说祝福 | 祝4月的你生日快乐
  10. 学AI买计算机,如何用免费GPU学习AI算法?这篇大集锦不要错过