题解 CF940A 【Points on the line】
此题之水,水于上青天
$(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】相关推荐
- 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 ...
- 北邮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 ...
- 【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 149. Max Points on a Line
LeetCode 149. Max Points on a Line Solution1: 参考花花酱:https://zxi.mytechroad.com/blog/geometry/leetcod ...
- [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 ...
- 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 ...
- 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. ...
- 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. ...
- leetcode 149. Max Points on a Line |149. 直线上最多的点数(Java)
题目 https://leetcode.com/problems/max-points-on-a-line/ 题解 hard 题,普通解法不难,有几个小坑: key : key : value 的存储 ...
最新文章
- tensorflow inceptionv3参数笔记
- spring cloud API网关
- Jmeter学习系列----1 环境搭建
- 深度学习的数学 (5)偏导数
- 深入理解计算机操作系统(一)
- linux代码段映射,bss,data,text,rodata,堆,栈,常量段与其各段在物理存储中关系
- CCF202112-1 序列查询
- win11在dev渠道升级怎么保留原来的文件 windows11渠道升级保留原文件的方法步骤
- php 卷积神经网络,PyTorch上实现卷积神经网络CNN的方法
- jq 遍历map集合
- 谷歌发布研究人口流动性的新方法【智能快讯】
- python怎么设置随机数种子_Pytorch在dataloader类中设置shuffle的随机数种子方式
- 机器学习是什么?详解机器学习概念
- [PC] 微软账号连接不上
- Eclipse中文语言包下载后怎么使用
- Spring Boot安装及使用(2021.10.28)
- 三位水仙花数 Python
- 2021考生如何做考博英语复习规划?
- bin文件和hex文件互转
- 使用VB.net将PNG图片转成icon类型图标文件
热门文章
- 【面试利器】 原生JS灵魂拷问,你能答上多少(一)
- Python基础1——读取数据(公众号数据科学实践)
- CLA not signed yet
- 1-18 Collections工具类和StreamAPI流式编程
- matlab画三维点坐标,已知各个点的三维坐标(x,y,z),怎么用MATLAB画三维图
- 我的世界服务器宝石系统,我的世界1.9-1.7宝石镶嵌插件
- 网络摄像头Androi端显示(mjpeg)源码分析
- Unity游戏开发工具的下载与安装
- svn没有绿色的对勾处理
- 第十九讲 信息安全管理【2021年软考-高级信息系统项目管理师】