[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 ...
随机推荐
- JAVA程序员面试笔试宝典4
1.HTTP中GET与POST方法有什么区别? GET方法上传数据时,数据添加在URL后面.同时,数据大小有限制,通常在1024Byte左右.POST方法传递数据是通过HTTP请求的附件进行的,传递的 ...
- ocelot+consul+identity4的使用demo
Ocelot网关搭建 搭建core控制台项目 本demo采用2.1版本 命名为APPIGateWay 在Nuget包中添加Ocelot引用 选用8.0.0版本 添加Ocelot.json 文件 内容为 ...
- Humidex POJ - 3299 (数学)
题目大意 给定你三个变量中的两个输出剩下的那一个 题解 没有什么,就是把公式推出来即可,完全的数学题 代码 #include <iostream> #include <cmath&g ...
- <MySQL>入门七 存储过程和函数
-- 存储过程和函数 /* 存储过程和函数:类似java中的方法 好处: 1.提高代码的重用性 2.简化操作 */ /* 存储过程 含义:一组预先编译好的SQL语句的集合.理解成批处理语句 1.提高代 ...
- Ztree加载完成默认选中根节点右侧生成表格
需求:页面加载完成之后,默认选中ztree的根节点,并执行其点击方法,右侧生成表格: 效果:如下图所示: 思路:在节点点击事件clickNode方法中根据节点的部门code查询这个部门下的所有员工,并 ...
- 1031. Hello World for U
Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. ...
- java,有用的代码片段
在我们写程序的过程中,往往会经常遇到一些常见的功能.而这些功能或效果往往也是相似的,解决方案也相似.下面是我在写代码的过程中总结的一些有用的代码片段. 1.在多线程环境中操作同一个Collection ...
- 教你 Shiro 整合 SpringBoot,避开各种坑
教你 Shiro 整合 SpringBoot,避开各种坑-----https://www.cnblogs.com/HowieYuan/p/9259638.html
- @Value取值为NULL的解决方案------https://blog.csdn.net/zzmlake/article/details/54946346
@Value取值为NULL的解决方案 https://blog.csdn.net/zzmlake/article/details/54946346
- yarn & vue-cli
yarn & vue-cli https://github.com/xgqfrms/ES6/issues/10 install https://yarnpkg.com/zh-Hans/docs ...