博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #408 (Div. 2)
阅读量:6633 次
发布时间:2019-06-25

本文共 5362 字,大约阅读时间需要 17 分钟。

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 nm, and k (2 ≤ n ≤ 100, 1 ≤ m ≤ n1 ≤ 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 = 3and house 6 are only 30 meters away, while house m = 3 and house 7 are 40 meters away.

女神家在m,你要买一套房子里女神家最近,其中为0的房子是你买不起的,找你能买得起的离女神家房子最近的距离。

#include 
using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);int n,m,k;cin>>n>>m>>k;int mi=1<<30;for(int i=1;i<=n;i++){ int p; cin>>p; if(p&&i!=m&&p<=k) mi=min(mi,abs(i-m));}cout<
<
View Code
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 nm, and k (2 ≤ n ≤ 106, 1 ≤ m ≤ n1 ≤ 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 ≤ nui ≠ 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.

B题看起来挺难的好像看不懂啊,其实就是简单的模拟,给你n个数,m个位置下有孔,然后再换,刚开始骨头在1号位置,有孔骨头就掉了。问最后骨头掉在哪里了

#include 
using namespace std;const int N=1e6+10;int a[N];int main(){ios::sync_with_stdio(false);cin.tie(0);int n,m,k;cin>>n>>m>>k;while(m--){ int x; cin>>x; a[x]=1;}int ans=1;while(k--){ int x,y; cin>>x>>y; if(x==ans){ if(!a[x]) ans=y; } else if(y==ans){ if(!a[y]) ans=x; }}cout<
View Code

 

 

 

 

转载于:https://www.cnblogs.com/BobHuang/p/6857365.html

你可能感兴趣的文章
CentOS6.4环境下布署LVS+keepalived笔记
查看>>
QQ地图api里的 地址解析函数 看不懂 javascript_百度知道
查看>>
软件版本管理
查看>>
安装配置NFS服务
查看>>
QEMU KVM Libvirt手册(6) – Network Block Device
查看>>
3中查询数据库连接数
查看>>
[原]Unity3D深入浅出 - 认识开发环境中的Component(组件)菜单
查看>>
CFileDialog的使用方法简单介绍
查看>>
基于Android 平台简易即时通讯的研究与设计[转]
查看>>
怎样解决MySQL数据库主从复制延迟的问题
查看>>
Redis安装
查看>>
dorado中的creationType选择类型
查看>>
java.utils.HashMap数据结构分析(转)
查看>>
JAVA思维导图系列:多线程0基础
查看>>
[转]搭建Maven私服
查看>>
Java NIO与IO
查看>>
实现两个数相加不用四则运算
查看>>
spring中配置了事务,数据业务层捕获异常,事务配置不成功?
查看>>
安卓开发之探秘蓝牙隐藏API(转)
查看>>
配置虚拟机网络的三种方式
查看>>