0519 G2n#W2B-A Buying A House
来源:互联网 发布:时间轴网页 源码 编辑:程序博客网 时间:2024/06/07 08:31
Buying A House
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 10meters 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.
The first line contains three integers n, m, and k (2 ≤ n ≤ 100, 1 ≤ m ≤ n, 1 ≤ 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.
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
5 1 200 27 32 21 19
40
7 3 5062 0 0 0 99 33 22
30
10 5 1001 0 1 0 0 0 0 0 1 1
20
In the first sample, with k = 20 dollars, Zane can buy only house 5. The distance from house m = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6than 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.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <memory.h>
#define MAX 102
using namespace std;
int n,m,k;
int ans=0;
int A[MAX];
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%d",&A[i]);
//printf("%d ",A[i]);
}
int dx;
for(dx=1; m+dx<=n||m-dx>=1; dx++){
//printf("\n%d-%d",m+dx,m-dx);
if(m+dx<=n && A[m+dx]<=k && A[m+dx]!=0){
ans=dx;//printf("HI");
break;
}
if(m-dx>=1 && A[m-dx]<=k && A[m-dx]!=0){
ans=dx;//printf("Hi");
break;
}
}
if(ans==0) printf("\nmk:%d-%d-ans:%d-dx:%d-",m,k,ans,dx);//imposable
else printf("%d",dx*10);
return 0;
}
- 0519 G2n#W2B-A Buying A House
- A. Buying A House
- A. Buying A House
- CodeForces 796A Buying A House
- 【Codeforces 796 A. Buying A House】
- Codeforces Round #408 A. Buying A House
- Buying A House (Codeforces-796A)
- 0519 G2n#W2B-D Valued Keys
- 0519 G2n#W2B-C Find The Bone
- 0519 G2n#W2B-B Vicious Keyboard
- Codeforces Round #408 (Div. 2) A Buying A House
- codeforces round#408(div.2) A. Buying A House
- Codeforces Round #408 (Div. 2) A. Buying A House
- 0519 G2n#W2A-A 解方程
- Codeforces Round #408 (Div. 2) A.Buying A House【模拟】水题~
- 0526 CF#400A&G2n#B
- 0526 CF#96A&G2n G- Football
- [Family]Buying a new car
- 汇编语言 :从键盘输入一个单个字符,显示该字符的ASCII码,回车键退出循环,终止程序
- linux内核的配置和编译
- Django 之 (2)视图与网址
- Error:Execution failed for task ':app:validateSigningDebug'
- ppt2016 关于拆分问题
- 0519 G2n#W2B-A Buying A House
- wordpress安装在子目录中,通过根目录访问
- nginx服务器安装搭建
- 关于Django 中启动自带服务器进入后台admin没有样式的问题...
- 测试
- Mongodb在ubuntu下的安装和启动和配置
- Openfire 4.1.2 DOWNLOADS
- [项目实训]SDUOJ的结构分析和Django进一步学习
- 实现input数字语音播报,可扩展成任何语音audio实现,IE8兼容转flash实现