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 ;
}

Codeforces Round #408 (Div. 2)(A.水,B,模拟)的更多相关文章

  1. Codeforces Round #408 (Div. 2) A B C 模拟 模拟 set

    A. Buying A House time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  3. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. Codeforces Round #365 (Div. 2) A 水

    A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)

    A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...

  7. Codeforces Round #408 (Div. 2)C. Bank Hacking(STL)

    题目链接:http://codeforces.com/problemset/problem/796/C 题目大意:有n家银行,第一次可以攻击任意一家银行(能量低于自身),跟被攻击银行相邻或者间接相邻( ...

  8. Codeforces Round #408 (Div. 2) C. Bank Hacking

    http://codeforces.com/contest/796/problem/C Although Inzane successfully found his beloved bone, Zan ...

  9. Codeforces Round #408 (Div. 2) D - Police Stations

    地址:http://codeforces.com/contest/796/problem/D 题目: D. Police Stations time limit per test 2 seconds ...

随机推荐

  1. 【java】实现一个简单的正则:判断一个字符串是否全由数字组成

    package 正则; public class TestIsNum { public static void main(String[] args) { String s1="abc&qu ...

  2. kendo ui grid选中行事件,获取combobox选择的值

    背景: 以前用 telerik ui做的grid现在又要换成kendo ui,不过说句实话kendo ui真的比telerik好多,可以说超级升级改头换面.当然用的mvc的辅助方法,以前的teleri ...

  3. 如何在yarn上运行Hello World(二)

      在之前的一篇文章我们介绍了如何编写在yarn集群提交运行应用的AM的yarnClient端,现在我们来继续介绍如何编写在yarn集群控制应用app运行的核心模块 ApplicationMaster ...

  4. lesson - 11 正则表达式

    正则就是有一定规律的字符串,有几个特殊符号很关键(. * + ? | ),我们平时不仅可以用命令行工具grep/sed/awk去引用正则,而且还可以把正则嵌入在nginx.apache.甚至php.p ...

  5. 前端学习_02_vps、web服务器、域名申请

    vps申请 国内比较好用的服务器:阿里云,青云:在国内申请ip比较方便,但是必须要备案域名,否则马上就会被封禁掉. 话说我也有点自己的思路想做个网站,服务器还真的是个问题. 小型的网站只需要ECS服务 ...

  6. JavaScript 计算指定月份有多少天

    用 js 画工作日历的时候,需要用 js 计算指定月份一共有多少天 在网上找了些方法,都比较繁琐,后来灵机一动,想到一个偷懒的办法,分享一下 一.原理分析 要想得到某月有多少天,只需要获取到当月最后一 ...

  7. python_第2课

    前言 回顾一下python+selenium基础,并整理相关知识点,分享给有需要,在前进道路上的朋友. 由于不是在python中敲的代码,有可能有缩进等相关错误,请自行检查 数据类型 #python中 ...

  8. Python之旅本地环境搭建

    刚开始学习Python, 之后将会把Python相关的一些学习在此记录下来 . 毋庸置疑 ,我们需要先搭建本地开发环境, 为之后的Python开发做准备 ,这篇文章 ,将环境的搭建记录下来 第一步: ...

  9. angular4.0项目文件解读

    这篇文章我觉得是很有用的,便于我们对ng项目的理解,同时在配置项目时,也能够很快的定位到相应文件. 摘录的别人的文章,首先感谢那个路人兄弟,下面就开始学习吧. File 文件 Purpose 用途 e ...

  10. 北漂的IT人

    北京的互联网人,是工作日完全没有个人生活的一类人,也是整个北漂大队伍中,下班时间最晚的那一波人,如果赶上周末还要加班,那毫不夸张地说,你的整个人生都在互联网上奋斗着. 虽说十点上班让多少行内外的人羡慕 ...