博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 796A
阅读量:1904 次
发布时间:2019-04-26

本文共 3108 字,大约阅读时间需要 10 分钟。

A. Buying A House
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.

The girl lives in house m of a village. There are n houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house n. The village is also well-structured: house i and house i + 1 (1 ≤ i < n) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.

You will be given n integers a1, a2, ..., an that denote the availability and the prices of the houses. If house i is occupied, and therefore cannot be bought, then ai equals 0. Otherwise, house i can be bought, and ai represents the money required to buy it, in dollars.

As Zane has only k dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.

Input

The first line contains three integers nm, and k (2 ≤ n ≤ 1001 ≤ m ≤ n1 ≤ k ≤ 100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 100) — denoting the availability and the prices of the houses.

It is guaranteed that am = 0 and that it is possible to purchase some house with no more than k dollars.

Output

Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.

Examples
input
5 1 200 27 32 21 19
output
40
input
7 3 5062 0 0 0 99 33 22
output
30
input
10 5 1001 0 1 0 0 0 0 0 1 1
output
20
Note

In the first sample, with k = 20 dollars, Zane can buy only house 5. The distance from house m = 1 to house 5 is10 + 10 + 10 + 10 = 40 meters.

In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house m = 3 and house 6 are only 30 meters away, while house m = 3 and house 7 are 40 meters away.

题意:很明显就是给你一列数,然后给你一个下标,给出你某某现在有多少钱,然后求最短距离,注意如果某个数的值为0的话这点是不能进行买卖的。

代码:

#include
using namespace std;const int INF=0x1f1f1f;const int maxn=105;int a[maxn];int main(){
int n,m,k; while(~scanf("%d%d%d",&n,&m,&k)) {
memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) {
scanf("%d",&a[i]); } int num=a[m]; int sum1=INF; int sum=0; int sum2=INF; for(int i=m+1;i<=n;i++) {
if(k>=a[i]&&a[i]!=0) {
sum1=i; break; } } for(int i=m-1;i>=1;i--) {
if(k>=a[i]&&a[i]!=0) {
sum2=i; break; } } sum1=abs(sum1-m); sum2=abs(sum2-m); sum=min(sum1,sum2); printf("%d\n",sum*10); } return 0;}

转载地址:http://ijncf.baihongyu.com/

你可能感兴趣的文章
学习笔记(14):一学即懂的计算机视觉(第一季)-Canny算子
查看>>
学习笔记(15):一学即懂的计算机视觉(第一季)-程序示例
查看>>
学习笔记(16):一学即懂的计算机视觉(第一季)-数学形态学扩展应用
查看>>
学习笔记(20):一学即懂的计算机视觉(第一季)-图像变换有什么用?
查看>>
QLineEdit和QDateTimeEdit等含编辑框使用stylesheet配置背景透明时,鼠标进入离开背景闪烁问题的解决
查看>>
使用Poco库进行加解密和签名验签
查看>>
走进开源代码(一)
查看>>
走进开源代码(二)
查看>>
[转]深度剖析闪电网络
查看>>
听李天飞《大话西游》有感
查看>>
走进开源代码(三)
查看>>
Linux下开发Qt界面程序时命令行传参数的一个坑
查看>>
strcasestr函数
查看>>
h264 ES流文件通过计算first_mb_in_slice区分帧边界
查看>>
设置系统时间
查看>>
C++模板学习和C++ 模板套模板
查看>>
合 JSONP 和 jQuery 快速构建强大的 mashup
查看>>
自制基于地图的 mashup
查看>>
成为优秀程序员的十个有效方法
查看>>
Oracle计算时间差函数
查看>>