A. Buying A House
来源:互联网 发布:十五米拉梯数据 编辑:程序博客网 时间:2024/06/17 13:35
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.
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 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.
额,水题。暴力解
代码如下:
//// main.cpp// A. Buying A House//// Created by 徐智豪 on 2017/4/18.// Copyright © 2017年 徐智豪. All rights reserved.//#include <iostream>#include <cmath>using namespace std;int n,m,k;int a[200];int fun( ){ int dis=10000; for(int i=1;i<=n;i++) { if(i==m||a[i]==0) continue; else if(a[i]<=k) { int temp=abs(i-m)*10; dis=dis<temp?dis:temp; } } return dis;}int main(int argc, const char * argv[]) { cin>>n>>m>>k; for(int i=1;i<=n;i++) cin>>a[i]; cout<<fun( )<<endl;; // cout<<0x7f<<endl; return 0;}
- A. Buying A House
- A. Buying A House
- CodeForces 796A Buying A House
- 0519 G2n#W2B-A Buying A House
- 【Codeforces 796 A. Buying A House】
- Codeforces Round #408 A. Buying A House
- Buying A House (Codeforces-796A)
- 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
- Codeforces Round #408 (Div. 2) A.Buying A House【模拟】水题~
- [Family]Buying a new car
- A. Round House
- A - Round House
- A. Round House
- Lesson23 A new house
- A. Round House 模拟
- 算法练习4:Buying a car
- 安装及启动redis
- import theano 导入失败的解决方法(+function用法)
- JSONObject使用方法详解
- sublime build 系统必读
- 浅谈面向对象的几个原则
- A. Buying A House
- android openvpn 编译文档
- windows上,python安装非官方包,提示error: Unable to find vcvarsall.bat
- usaco Calf Flac(O(n)时间求回文串长度)
- day73_easyui
- Oracle 基本操作二:内连接,左连接,右连接,自连接,集合查询(union)
- Python--爬取一个百度贴吧的图片(风景吧)
- 《统计学习方法》——kd树python实现
- AlexNet结构详解(引用MrGiovanni博士)