[题目链接]

https://codeforces.com/contest/1004/problem/A

[算法]

直接按题意模拟即可

时间复杂度 :O(NlogN)

[代码]

#include<bits/stdc++.h>
using namespace std;
#define MAXN 110
const int inf = 1e9; int n,d;
int a[MAXN];
set< int > ans; template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline bool ok(int x)
{
int i;
int ret = inf;
for (int i = ; i <= n; i++) ret = min(ret,abs(a[i] - x));
return ret == d;
} int main()
{ read(n); read(d);
for (int i = ; i <= n; i++) read(a[i]);
for (int i = ; i <= n; i++)
{
if (ok(a[i] - d)) ans.insert(a[i] - d);
if (ok(a[i] + d)) ans.insert(a[i] + d);
}
printf("%d\n",(int)ans.size()); return ; }

[Codeforces Round495A] Sonya and Hotels的更多相关文章

  1. Codeforces 714C. Sonya and Queries Tire树

    C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...

  2. Codeforces 713A. Sonya and Queries

    题目链接:http://codeforces.com/problemset/problem/713/A 题意: Sonya 有一个可放置重复元素的集合 multiset, 初始状态为空, 现给予三种类 ...

  3. Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)

    [题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...

  4. CodeForces 1151F Sonya and Informatics

    题目链接:http://codeforces.com/problemset/problem/1151/F 题目大意: 给定长度为 n 的 01 序列,可以对该序列操作 k 次,每次操作可以交换序列中任 ...

  5. Codeforces 713C Sonya and Problem Wihtout a Legend DP

    C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...

  6. Codeforces C. Sonya and Problem Wihtout a Legend(DP)

    Description Sonya was unable to think of a story for this problem, so here comes the formal descript ...

  7. Codeforces 713C Sonya and Problem Wihtout a Legend(DP)

    题目链接   Sonya and Problem Wihtout a Legend 题意  给定一个长度为n的序列,你可以对每个元素进行$+1$或$-1$的操作,每次操作代价为$1$. 求把原序列变成 ...

  8. [Codeforces Round495B] Sonya and Exhibition

    [题目链接] https://codeforces.com/contest/1004/problem/B [算法] 不难发现 , 最优解一定是01010101.... 时间复杂度 : O(N) [代码 ...

  9. codeforces 495D Sonya and Matrix

    Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...

随机推荐

  1. MySQL单表数据不超过500万:是经验数值,还是黄金铁律?

    今天,探讨一个有趣的话题:MySQL 单表数据达到多少时才需要考虑分库分表?有人说 2000 万行,也有人说 500 万行.那么,你觉得这个数值多少才合适呢? 曾经在中国互联网技术圈广为流传着这么一个 ...

  2. ThinkPHP---TP功能类之上传

    [一]概论 (1)上传操作的核心操作:移动临时文件(move_upload_file),在ThinkPHP里封装了上传类Upload.class.php (2)上传类Upload.class.php代 ...

  3. 代码分析工具splint安装介绍

    官网 http://www.splint.org/ splint能干什么? splint是一个静态检查C语言代码安全弱点和编写错误的开源程序.(不支持C++) splint会进行多种常规检查,包括 空 ...

  4. JAVA基础——Native关键字

    一:native声明 在Java中native是关键字.它一般在本地声明,异地用C和C++来实现.它的声明有几点要注意: 1)native与访问控制符前后的关系不受限制. 2)必须在返回类型之前. 3 ...

  5. C++ 类的初始化列表

    class Animal{public: Animal(int weight,int height): //A初始化列表 m_weight(weight), m_height(height) { } ...

  6. UVA-12333 Revenge of Fibonacci(竖式加法模拟 & 字典树)

    题目: 给出一个斐波那契数字的前缀,问第一个有这个前缀的数字在斐波那契数列中是第几个. 思路: 紫书提示:本题有一定效率要求.如果高精度代码比较慢,可能会超时. 利用滚动数组和竖式加法来模拟斐波那契相 ...

  7. Linux命令rsync使用总结

    详细用法见:https://www.cnblogs.com/oboth-zl/articles/10334754.html rsync命令简介 主要用于数据同步.备份和镜像,除了本地使用之外,也可以通 ...

  8. 爬虫----Web_WeChat

    流程: 打开的web_wechat,就有出现二维码,在network中,name中login?loginicon中,status的状态是pending,pending的意思是前端发送了一个请求,但是还 ...

  9. 洛谷 4302 BZOJ 1090 SCOI2003 字符串折叠 UVA1630 Folding(输出方案版)

    [题解] 区间DP.  设f[i][j]表示i~j的最小代价.再枚举中间点k,很容易想到转移方程为f[i][j]=min(f[i][j],f[i][k]+f[k][j]),同时如果i~k可以通过重复获 ...

  10. photon Unity RPC 调用流程

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/51425225 作者:car ...