https://codeforces.com/contest/1133/problem/C

题解:尺取法

参考文章:https://blog.csdn.net/weixin_43272781/article/details/83717797

C++版本一

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp,sum;
int a[N];
char str;
struct node{};
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}sort(a+1,a+n+1);int pos=1;int len=1;for(int i=2;i<=n;i++){if(abs(a[pos]-a[i])<=5){len++;}else{ans=max(len,ans);while(abs(a[++pos]-a[i])>5);len=i-pos+1;}}ans=max(len,ans);cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}

C++版本二

优化版本

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp,sum;
int a[N];
char str;
struct node{};
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}sort(a+1,a+n+1);int l=1;int r=1;while(l<=r&&r<=n){if(a[r]-a[l]<=5){ans=max(r-l+1,ans);r++;}else{l++;}}//ans=max(r-l+1,ans);cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}

Balanced Team相关推荐

  1. HTML期末学生大作业-乒乓球网页作业html+css+javascript

    一.部分网页截图 二.部分源代码 <div id="cbx-aboutus" class="cbx-section cbx-aboutus">< ...

  2. How DICK’S moved its software development in-house and aced omnichannel retail

    Learn about Pivotal Labs Pivotal is now part of VMware, so some of these products and services are n ...

  3. Codeforces Round 1133(Div.3)题解

    A 思路 做法显然,但是需要注意一些小的细节: ①不能输出如"2:2"这样的时间,必须输出"02:02"这样的时间: ②中间的冒号是":", ...

  4. Mind the GAP: A Balanced Corpus of Gendered Ambiguous Pronouns--论文笔记

    Mind the GAP: A Balanced Corpus of Gendered Ambiguous Pronouns 注意差距: 性别歧义代词的平衡语料库 Abstract Coreferen ...

  5. Visual Studio 2005 Team System下载地址

    注册一个msn就可以去微软下载了,关于替换序列号变成正版的方法我没有试,team suite 我在用,但Team Foundation Server 我还没有安装好 Microsoft Visual ...

  6. 高级网络配置《 bond team桥接 》的建立

    bond 资料详情 一.链路聚合:以太网链路聚合简称链路聚合,它通过将多条以太网物理链路捆绑在一起成为一条逻辑链路,从而实现增加链路带宽的目的.同时,这些捆绑在一起的链路通过相互间的动态备份,可以有效 ...

  7. 安装Team Services Agent Win7

    现状:项目现时使用的是Team Services,使用Team Services可以控制其中的一台Build Server,从Github提取代码,并在Build Server进入编译打包处理(son ...

  8. SP11469 SUBSET - Balanced Cow Subsets(折半搜索+状态压缩)难度⭐⭐⭐⭐★

    题目链接 SP11469 SUBSET - Balanced Cow Subsets 题目翻译 给出N(1≤N≤20)N(1≤N≤20)N(1≤N≤20)个数M(i)(1<=M(i)<=1 ...

  9. 微软MSIT部门招Sr SDE for FSS team

    Job Description: Qualifications Do you want to design and build the services and solutions that are ...

最新文章

  1. 【 MATLAB 】Fourier Transforms ( fft )
  2. 如何使自己的程序只运行一次
  3. 全排列 (C语言实现)
  4. 我肝了一个月,给你写出了这本Java开发手册。
  5. 【Qt】Qt5.9编译MySQl5.7驱动
  6. android 7.0编译报错,编译android7.0 sdk错误解决方法
  7. 解决Firefox访问EBS时提示激活Java插件的问题
  8. java获取达梦数据库_记一次对达梦数据库的优化过程
  9. python得安什么安装包_初学 Python 需要安装哪些软件?
  10. 什么是多线程,锁,死锁,怎么避免死锁(转)
  11. (模电笔记二 By Multisim)波特图(Bode Plotter)幅频特性相频特性详解
  12. 飞天2.0面向万物智能的操作系统正式启幕
  13. tar --exclude用法
  14. 孙子算经-秦王暗点兵问题
  15. 计算机软件水平考试(软考)-程序员介绍
  16. ARM使用术语清除(flush)和清理(clean)表示对cache的两种基本操作
  17. adb 删除文件时提示Read-only file system问题【not in /proc/mounts】
  18. 人工智能换脸python_Python实现AI换脸功能
  19. php引擎,PHP撮合引擎
  20. 日语的文艺与娱乐休闲

热门文章

  1. python语言支持苹果系统吗_Mac系统上的一款Python编程平台
  2. c 语言中下标运算符,详解C++中二进制求补运算符与下标运算符的用法
  3. 电脑功耗测试软件_聊一款“躺着都中枪”的笔记本电脑
  4. caj在线阅读_用翻译软件快速阅读大量英文文献
  5. java list clear 垃圾回收_list.clear()vs list = new ArrayList Integer(); [重复]
  6. mfc制作登录界面mysql_MFC制作漂亮界面之登录界面
  7. mysql每一步花费时间_MySQL之:日志
  8. hibernate mysql id 自增长 注解_hibernate Mysql 自增长 注解配置,表无关联的注解方式关联查询...
  9. 三、HDFS中的Java和Python API接口连接
  10. sklear多项式回归