[Codeforces Round495A] Sonya and Hotels
[题目链接]
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的更多相关文章
- Codeforces 714C. Sonya and Queries Tire树
C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...
- Codeforces 713A. Sonya and Queries
题目链接:http://codeforces.com/problemset/problem/713/A 题意: Sonya 有一个可放置重复元素的集合 multiset, 初始状态为空, 现给予三种类 ...
- Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)
[题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...
- CodeForces 1151F Sonya and Informatics
题目链接:http://codeforces.com/problemset/problem/1151/F 题目大意: 给定长度为 n 的 01 序列,可以对该序列操作 k 次,每次操作可以交换序列中任 ...
- 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 ...
- 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 ...
- Codeforces 713C Sonya and Problem Wihtout a Legend(DP)
题目链接 Sonya and Problem Wihtout a Legend 题意 给定一个长度为n的序列,你可以对每个元素进行$+1$或$-1$的操作,每次操作代价为$1$. 求把原序列变成 ...
- [Codeforces Round495B] Sonya and Exhibition
[题目链接] https://codeforces.com/contest/1004/problem/B [算法] 不难发现 , 最优解一定是01010101.... 时间复杂度 : O(N) [代码 ...
- codeforces 495D Sonya and Matrix
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...
随机推荐
- Vue渲染原理
现在基本所有的框架都已经认同这个看法——DOM应尽可能是一个函数式到状态的映射.状态即是唯一的真相,而DOM状态只是数据状态的一个映射.如下图所示,所有的逻辑尽可能在状态的层面去进行,当状态改变的时候 ...
- 【原】thinkphp修改Redis操作类,支持选择数据库功能及添加其他方法
版本3.2.2(ThinkPHP\Library\Think\Cache\Driver\Redis.class.php), 一:官方默认不支持选择数据库功能及,现就可选择数据库功能进行说明. 1 co ...
- 微服务网关从零搭建——(六)ocelot配置追踪功能
butterfly 准备工作 首先下载buterfly release版本 解压并通过命令启动:dotnet Butterfly.Web.dll --EnableHttpCollector=true ...
- you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(255), sort integer not null
you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version ...
- eclipse 中为 java 项目生成 API 文档、JavaDoc
当我们的项目很大,编写了很多代码的时候,就需要生成一个标准的 API 文档,让后续的开发人员,或者合作者可以清晰的了解您方法的使用. 1.点击 eclipse 的 Project 菜单,选择 Gene ...
- 洛谷 2633 BZOJ 2588 Spoj 10628. Count on a tree
[题解] 蜜汁强制在线... 每个点开一个从它到根的可持久化权值线段树.查询的时候利用差分的思想在树上左右横跳就好了. #include<cstdio> #include<algor ...
- http://localhost/main/company/jurtion---外卖权限添加
http://localhost/main/company/jurtion---外卖权限添加
- Android ToggleButton:状态切换的Button
Android ToggleButton:状态切换的Button Android ToggleButton和Android Button类似,但是ToggleButton提供了一种选择机制,可以 ...
- 常州模拟赛d5t3 appoint
分析:这道题比较奇葩.因为字符串没有swap函数,所以一个一个字符串交换只有30分.但是我们可以不用直接交换字符串,而是交换字符串的指针,相当于当前位置是哪一个字符串,每次交换int,可以拿60分. ...
- [K/3Cloud] 如何在k3Cloud主页实现自定义页面的开发
过自定义页签动态添加一些内容,比如网页链接.图片等. 如果是动态的增加链接,可以参考一下代码,然后在ButtonClick事件里面对链接进行处理. public override void After ...