Codeforces Round #408 (Div. 2) A.Buying A House【模拟】水题~
来源:互联网 发布:python3防止sql注入 编辑:程序博客网 时间:2024/06/05 10:25
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 aren houses in that village, lining in a straight line from left to right: house1, house 2, ..., housen. The village is also well-structured: housei and house i + 1 (1 ≤ i < n) are exactly10 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 housei is occupied, and therefore cannot be bought, thenai equals0. Otherwise, house i can be bought, andai 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 thank 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 house5. The distance from house m = 1 to house5 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.
题目大意:
给你N个房子,每个房子的价格为a【i】.a【i】==0的表示不能购买,现在他的位子在m,有k钱.他想买一个房子,使得这个房子尽可能的靠近m这个位子。
现在设定两个房子间的距离为10.
思路:
直接暴力模拟即可。
Ac代码:
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;int a[150];int main(){ int n,m,k; while(~scanf("%d%d%d",&n,&m,&k)) { int output=0x3f3f3f3f; for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=m;i<=n;i++) { if(a[i]!=0) { if(a[i]<=k)output=min(output,(i-m)*10); } } for(int i=m;i>=1;i--) { if(a[i]!=0) { if(a[i]<=k)output=min(output,(m-i)*10); } } printf("%d\n",output); }}
- 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
- Codeforces Round #408 A. Buying A House
- Codeforces Round #346 (Div. 2) -A. Round House(模拟)
- Codeforces Round #346 (Div. 2)--A. Round House
- Codeforces Round #346 (Div. 2) A.Round House
- Codeforces Round #346 (Div. 2) A. Round House
- Codeforces Round #346 (Div. 2) - A Round House
- Codeforces Round #346 (Div. 2) A. Round House
- Codeforces Round #346 (Div. 2) A. Round House
- CodeForces 796A Buying A House
- 【Codeforces 796 A. Buying A House】
- Buying A House (Codeforces-796A)
- Codeforces 659A Round House (模拟)
- Codeforces Round #297 (Div. 2) A(模拟)
- Codeforces Round #340 (Div. 2)(A) 模拟
- 3.3(1.委托 2.事件 3.字典)
- adb shell 相关,持续更新
- ubuntu16.04 apt-get 速度慢问题
- 第五届蓝桥杯java程序设计 c组决赛试题 年龄巧合
- CJOJ 1217 【HAOI2005】路由选择问题
- Codeforces Round #408 (Div. 2) A.Buying A House【模拟】水题~
- UICollectionView拾遗
- 数据结构课下复习1
- swust.oj.1075
- 飞翔nyoj195
- Lightoj1111——Best Picnic Ever(dfs)
- linux动态库及静态库的制作和makefile的简单编写
- [LintCode]Maximum Subarray III
- Android 唯一设备号生成方案