CodeForces - 796A Buying A House
思路:从m直接向两边枚举,如果当前点需要的费用小于等于k,说明一定是最近距离。
AC代码
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 100 + 5;
int a[maxn];
int main() {
int n, m, k;
while(scanf("%d%d%d", &n, &m, &k) == 3) {
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
int ans;
for(int i = 1; i < n; ++i) {
if(m-i > 0 && a[m-i] <= k && a[m-i]) {
ans = i;
break;
}
if(m+i <= n && a[m+i] <= k && a[m+i]) {
ans = i;
break;
}
}
printf("%d\n", ans*10);
}
return 0;
}
如有不当之处欢迎指出!
CodeForces - 796A Buying A House的更多相关文章
- 【codeforces 796A】Buying A House
[题目链接]:http://codeforces.com/contest/796/problem/A [题意] 让你选一个最靠近女票的,且能买的房子; 输出你和你女票的距离; [题解] 枚举 [Num ...
- CodeForces - 799B-T-shirt buying (优先队列)
题目链接 /* Name: Copyright: Author: Date: 2018/5/2 16:09:54 Description:优先队列 */ #include <iostream&g ...
- codeforces 796A-D
决定在 codeforces 练题啦,决定每个比赛刷前四道...太难就算了 796A Buying A House 题意:给出x轴上的n 个点,每个点有个权值,问离m 点最近的权值小于等于k 的点离m ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
- Codeforces 1136D - Nastya Is Buying Lunch - [贪心+链表+map]
题目链接:https://codeforces.com/problemset/problem/1136/D 题意: 给出 $1 \sim n$ 的某个排列 $p$,再给出若干 $(x,y)$ 表示当序 ...
- 【codeforces 103E】 Buying Sets
http://codeforces.com/problemset/problem/103/E (题目链接) 题意 给出$n$个数,每个数与一个集合相关联.从其中选出最小的若干个数,选出的数的个数与这些 ...
- Codeforces 799B - T-shirt buying(STL)
题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...
- Codeforces Round #413 B. T-shirt buying
B. T-shirt buying time limit per test 3 seconds memory limit per test 256 megabytes A new pack ...
- CodeForces - 799B T-shirt buying 【贪心】
题目链接 http://codeforces.com/problemset/problem/799/B 题意 给出N件衣服 pi 表示 第i件衣服的价格 ai 表示 第i件衣服的前面的颜色 bi 表示 ...
随机推荐
- greedy算法(python版)
greedy算法的核心思想是首先计算覆盖面大的部分,然后依次寻找其他覆盖面最大的部分.该算法的使用场景就像他的名字一样,当符合贪婪属性的时候就可以考虑. states_needed = set(['北 ...
- CDuiString和String的转换
很多时候 难免用到CDuiString和string的转换. 我们应该注意到,CDuiString类有个方法: LPCTSTR GetData() const; 可以通过这个方法,把CDuiStrin ...
- junit设计模式--适配器模式
适配器(Adapter)模式 在软件系统中,由于环境的变化,常常需要将"一些现存的对象"放在新的环境中应用,但是新环境要求的接口是这些现存对象所不满足的.那么如何应对这种" ...
- Java常用类--处理日期
Date Date类在java.util包中.使用Date类的无参数构造方法创建的对象可以获取本地当前时间.一般来说,也只使用这个.因为date的很多方法都已经不推荐使用了,所以Date的功能大大的消 ...
- Centos 7 安装 memcached
一.准备工作: 安装之前确保你的系统上已经安装libevent和telnet· 1.测试是否安装telnet: # rpm -qa |grep telnet 如果显示结果为: telnet-0.17- ...
- Hibernate (四)
1 懒加载 (感觉用处不是很大) 需要的时候加载,不需要的时候就不加载. 1.1 环境的搭建 hibernate.cfg.xml <?xml version='1.0' encoding='ut ...
- Windows--查看使用某端口的进程
场景: 有时候我们希望查找某个端口被那个进程使用,如何操作呢? 比如查找8000端口被按个进程使用? 首先使用netstat -ano |grep 8000查看 13776就是使用的进程ID 然后使用 ...
- Round trip 流程图
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢!
- SpringMVC源码情操陶冶-DispatcherServlet
本文对springmvc核心类DispatcherServlet作下简单的向导,方便博主与读者查阅 DispatcherServlet-继承关系 分析DispatcherServlet的继承关系以及主 ...
- linux中sed在指定字符前后添加内容
假设文档内容如下: [root@localhost ~]# cat /tmp/input.txt null 000011112222 test 要求:在1111之前添加AAA,方法如下: sed ...