思路:从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. linkin大话数据结构--字符串,数组,list之间的互转

    在实际开发中,我们经常会用到字符串,字符数组,字符list,当然也会不可避免的进行这3者之间的互相转换. 在使用到Apache和Google下的common包,可以这样子实现: package tz. ...

  2. tcpdump 使用

    例子: 首先切换到root用户 tcpdump -w  aaa.cap   -i eth7   -nn -x  'port  9999'  -c  1 以例子说明参数: -w:输出到文件aaa.cap ...

  3. VisionPro学习笔记:用IEEE1394相机抓取图像

    1)找到采集卡: CogFrameGrabber1394DCAMs cameras = new CogFrameGrabber1394DCAMs(); 2)列举相连接的相机: ICogFrameGra ...

  4. 嵌套for in循环组合cat方式文件中包含空格问题

    关于循环嵌套使用for循环的空格问题 原创不易,转载请注明 需求: 现有两个功文件,需要将文件拼接 [root@localhost ~]# cat name 111 222 223 333 444 5 ...

  5. 【转】centos安装vim7.4

    centos安装vim7.4   系统版本centos6.4; root权限 su - root     卸载 $ rpm -qa | grep vim $ yum remove vim vim-en ...

  6. H5 Canvas图像模糊解决办法

    1.最近在用h5的canvas画动画,发现图像特别模糊.后来终于找到罪魁祸首是<meta name="viewport" content="width=device ...

  7. Spring 当 @PathVariable 遇上 【. # /】等特殊字符

    @PathVariable注解应该不是新鲜东西了Spring3.0就开始有了 URL中通过加占位符把参数传向后台 举个栗子,如下比较要说的内容比较简单就大概齐的写一下 画面侧 $.ajax({ typ ...

  8. spring之AspectJ基于注解 AOP编程

    一.前言 使用注解代替之前在spring配置文件中配置目标类.切面类和aop配置. 二.注意 需要注意的是,需要在spring配置文件中引入如下,如果不添加,切面类中的@Aspect注解将不起作用 & ...

  9. vsftp实现只能上传不能下载、删除权限配置

    vsftpd可以对每个用户特别限制.只要给那个用户建立一个设置文件,然后在文件里设置 在vsftpd.conf里加user_config_dir=/etc/vsftpd/vsftpd_user_con ...

  10. Spring源码情操陶冶-PropertyPlaceholderBeanDefinitionParser注解配置解析器

    本文针对spring配置的context:property-placeholder作下简单的分析,承接前文Spring源码情操陶冶-自定义节点的解析 spring配置文件应用 <context: ...