思路:从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的更多相关文章

  1. 【codeforces 796A】Buying A House

    [题目链接]:http://codeforces.com/contest/796/problem/A [题意] 让你选一个最靠近女票的,且能买的房子; 输出你和你女票的距离; [题解] 枚举 [Num ...

  2. CodeForces - 799B-T-shirt buying (优先队列)

    题目链接 /* Name: Copyright: Author: Date: 2018/5/2 16:09:54 Description:优先队列 */ #include <iostream&g ...

  3. codeforces 796A-D

    决定在 codeforces 练题啦,决定每个比赛刷前四道...太难就算了 796A Buying A House 题意:给出x轴上的n 个点,每个点有个权值,问离m 点最近的权值小于等于k 的点离m ...

  4. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

  5. Codeforces 1136D - Nastya Is Buying Lunch - [贪心+链表+map]

    题目链接:https://codeforces.com/problemset/problem/1136/D 题意: 给出 $1 \sim n$ 的某个排列 $p$,再给出若干 $(x,y)$ 表示当序 ...

  6. 【codeforces 103E】 Buying Sets

    http://codeforces.com/problemset/problem/103/E (题目链接) 题意 给出$n$个数,每个数与一个集合相关联.从其中选出最小的若干个数,选出的数的个数与这些 ...

  7. Codeforces 799B - T-shirt buying(STL)

    题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...

  8. 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 ...

  9. CodeForces - 799B T-shirt buying 【贪心】

    题目链接 http://codeforces.com/problemset/problem/799/B 题意 给出N件衣服 pi 表示 第i件衣服的价格 ai 表示 第i件衣服的前面的颜色 bi 表示 ...

随机推荐

  1. scrapy_ItemLoader

    什么是Itemloader? 一种容器,实现直白高效字段提取 直接赋值取值的方式,会出现一下几个问题 代码量一多,各种css和xpath选择器,充斥整个代码逻辑,没有规则,不利于维护 对于一个字段的预 ...

  2. .net Core学习笔记2 实现列表的条件筛选,排序,分页

    打开vs,完善上次"简单粗暴"的项目 发现上次的实体类的导航属性有点问题,这是更改后的 namespace ProductMvc.Models { public class Pro ...

  3. Linux指令--grep

    原文地址:http://www.cnblogs.com/peida/archive/2012/12/17/2821195.html.感谢作者的无私分享. Linux系统中grep命令是一种强大的文本搜 ...

  4. ClearCase新增文件

    原文地址:http://blog.csdn.net/ace_fei/article/details/7531376 大家应该都知道在clearcase上新增文件是通过以下过程来生成的: clearto ...

  5. java时间格式转化(毫秒 to 00:00)

    把秒数转换为%d:%02d:%02d 格式 private String stringForTime(int timeSec) { int totalSeconds = timeSec; int se ...

  6. pulltorefresh 设置刷新文字提示颜色

     xmlns:ptr="http://schemas.android.com/apk/res-auto" 赵泽民 2016/7/12 15:48:58 ptr:ptrHeaderS ...

  7. python-networkx学习(1)

    介绍: networkx是python的一个库,它为图的数据结构提供算法.生成器以及画图工具.近日在使用ryu进行最短路径获取,可以通过该库来简化工作量.该库采用函数方式进行调用相应的api,其参数类 ...

  8. zabbix action理解

    Maintenance status not in maintenance   谷歌翻译:维护状态不在维护中,中文意思就是监控的设备有problem,触发器报警了,然后执行action {TRIGGE ...

  9. TCP那些事儿(上)

    TCP是一个巨复杂的协议,因为他要解决很多问题,而这些问题又带出了很多子问题和阴暗面.所以学习TCP本身是个比较痛苦的过程,但对于学习的过程却能让人有很多收获.关于TCP这个协议的细节,我还是推荐你去 ...

  10. AppScan 扫描测试策略

    使用 AppScan 进行扫描 针对大型网站的扫描,我们按照戴明环 PDCA 的方法论来进行规划和讨论,建议 AppScan 使用步骤:计划(Plan).执行(Do).检查(check).分析(Ana ...