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 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.

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 20 
0 27 32 21 19
Output
40
Input
7 3 50 
62 0 0 0 99 33 22
Output
30
Input
10 5 100 
1 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 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.

题目链接:http://codeforces.com/contest/796/problem/A

分析:题意:给你n m k  依次给你n个房子的价格 现在找离第m个房子最近的 价格不超过k 的距离 两个相邻的房子之间的距离为10

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m,k;
int a[];
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int minn=1e+;
for(int i=;i<=n;i++)
{
if(a[i]!=&&k>=a[i])
{
minn=min(minn,abs(m-i)*);
}
}
printf("%d\n",minn);
}
return ;
}
B. Find The Bone
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Zane the wizard is going to perform a magic show shuffling the cups.

There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i.

The problematic bone is initially at the position x = 1. Zane will confuse the audience by swapping the cups k times, the i-th time of which involves the cups at the positions x = ui and x = vi. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations.

Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at x = 4 and the one at x = 6, they will not be at the position x = 5 at any moment during the operation.

Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.

Input

The first line contains three integers n, m, and k (2 ≤ n ≤ 106, 1 ≤ m ≤ n, 1 ≤ k ≤ 3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.

The second line contains m distinct integers h1, h2, ..., hm (1 ≤ hi ≤ n) — the positions along the x-axis where there is a hole on the table.

Each of the next k lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the positions of the cups to be swapped.

Output

Print one integer — the final position along the x-axis of the bone.

Examples
Input
7 3 4 
3 4 6
1 2
2 5
5 7
7 1
Output
1
Input
5 1 2 
2
1 2
2 4
Output
2
Note

In the first sample, after the operations, the bone becomes at x = 2, x = 5, x = 7, and x = 1, respectively.

In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.

题目链接:http://codeforces.com/contest/796/problem/B

分析:

题意: 桌子上倒着摆着n个杯子  初始骨头放在第一个杯子下 有m个杯子下有洞  骨头会掉入洞中 k次操作 每次交换两个杯子的位置(连同可能有的骨头) 问你经过k次操作之后 骨头在哪个杯子下面?

题解:模拟 注意第一个杯子下有洞的情况。

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int n,m,k,x,y,t;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
for(int i=;i<=m;i++)
{
scanf("%d",&t);
a[t]=;
}
int ans=;
for(int i=;i<=k;i++)
{
scanf("%d%d",&x,&y);
if(a[ans]==)
continue;
if(ans==x)
ans=y;
else if(ans==y)
ans=x;
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. JaveScript-解决表格使用滚动条时冻结表头栏问题
  2. JS监听输入框值变化兼容 onpropertychange、oninput
  3. 【统计学习】SVM之超平面方程来源
  4. oracle安装不容易啊
  5. 移动端自动化环境搭建-wxpython的安装
  6. ahjesus Ubuntu配置svn服务器
  7. python实现动态更新远程机器列表的SSH登录脚本
  8. BI测试工具之跨数据库数据对比,支持oracle,sqlserver
  9. bzoj3036: 绿豆蛙的归宿
  10. 微信php接入设计案列
  11. maven添加oracle jdbc依赖
  12. 【转】Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask
  13. Week7(10月21日)
  14. Openjudge-计算概论(A)-求一元二次方程的根
  15. 学习笔记TF028:实现简单卷积网络
  16. Https系列之三:让服务器同时支持http、https,基于spring boot
  17. vue 组件动态 循环
  18. OpenLDAP一登录系统就修改密码
  19. [leetcode]83. Remove Duplicates from Sorted List有序链表去重
  20. Study 5 —— 流程控制

热门文章

  1. iOS NSString 文本不同的颜色 标题+文本字体大小 行间距/删除不需要的字符 /以及自适应高度
  2. 为什么CPU需要时钟这种概念?
  3. Git安装和使用(谨记)
  4. UVALive 3177 Beijing Guards
  5. Achartengine.jar绘制动态图形一 --饼图
  6. Maven安装教程
  7. webpack3.x基本配置与总结
  8. c# 去除字符串中重复字符
  9. Python函数参数的五种类型
  10. javascript函数与表达式