[题目链接]

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. Vue2.0 —生命周期和钩子函数

    vue生命周期简介 咱们从上图可以很明显的看出现在vue2.0都包括了哪些生命周期的函数了. 生命周期探究 对于执行顺序和什么时候执行,看上面两个图基本有个了解了.下面我们将结合代码去看看钩子函数的执 ...

  2. struts2源码下载链接

    http://blog.csdn.net/qq_qun_247286682/article/details/6975298

  3. 最大子段和(洛谷P1115,动态规划递推)

    洛谷题目链接 题目赋值出来格式有问题,所以我就只放题目链接了 下面为ac代码 #include<bits/stdc++.h> #define ll long long using name ...

  4. QQ浏览器占用资源真的大

    Edge 和 QQ浏览器 对比 正常情况下: QQ浏览器 看1个直播频道 ,CPU就几乎是在90% usage 范围 ,看2 个 就非常卡 下面就是对比图 Edge 我个人觉得 Edge 比 QQ好用 ...

  5. MySQL4

    MySQL数据库4 1 管理索引 创建索引帮助 help CREATE INDEX 创建索引 指令 CREATE INDEX 语法格式 CREATE INDEX index_name ON tbl_n ...

  6. 洛谷 3959 宝藏 NOIP2017提高组Day2 T2

    [题解] 状压DP. f[i]表示现在的点是否连接的状态是i. #include<cstdio> #include<cstring> #include<algorithm ...

  7. 洛谷 2471 BZOJ 1067 [SCOI2007]降雨量

    [题解] 用线段树维护区间最大值(因为没有修改,St表也可以),然后由于x,y可能是降雨量未知的年份,需要进行分类讨论. #include<cstdio> #include<algo ...

  8. Java Arrays.sort相关用法与重载

    Java Arrays.sort() Java中的数组排序函数, 头文件 import java.util.Arrays; 相关API Arrays.sort(arys[]) Arrays.sort( ...

  9. 【Codeforces 442B】Andrey and Problem

    [链接] 我是链接,点我呀:) [题意] n个朋友 第i个朋友帮你的概率是pi 现在问你恰好有一个朋友帮你的概率最大是多少 前提是你可以选择只问其中的某些朋友不用全问. [题解] 主要思路是逆向思维, ...

  10. J2EE 课件2

    1.JSP页面可由5种元素组合而成: ① 普通的HTML标记符: ② JSP标记,如指令标记.动作标记: ③ 变量和方法的声明: ④ Java程序片: ⑤ Java表达式 2.声明变量和方法 JSP页 ...