Codeforces 796A
来源:互联网 发布:7z解压软件 mac专用 编辑:程序博客网 时间:2024/06/18 18:20
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
![](http://codeforces.com/predownloaded/a3/67/a367b62bc4b16beda53f933d94f91593af426370.png)
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 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<bits/stdc++.h>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;}
- Codeforces 796A
- CodeForces 796A Buying A House
- 【Codeforces 796 A. Buying A House】
- Buying A House (Codeforces-796A)
- CodeForces-a
- Codeforces 903A A
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- codeforces#99 a
- codeforces 105 div2 A
- codeforces #121 A
- 玩转Excel系列-index+match查找函数用法
- 霍夫曼编码与priority_queue的千丝万缕
- Ubuntu下SVN的安装及使用方法
- Android WebView 开发详解(三)
- Jenkins+Maven+Git+Tomcat快速搭建持续集成环境
- Codeforces 796A
- 微信小程序从注册到上线系列专题
- 单链表——基本操作(求表长、查找、插入、删除)(java)
- 使用json生成Bootstrap无限极导航菜单
- mySql 查询当天、本周、最近7天、本月、最近30天的语句
- jsp中C标签的使用用例
- 第三十三讲项目四 多数中的最大
- android自定义绘图控件,绘图所占画布比例过小
- 安卓环境配置