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.

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

题解:水

 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
int n,m,k;
int a[];
int main()
{
scanf("%d %d %d",&n,&m,&k);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int ans=;
for(int i=m+;i<=n;i++)
{
if(a[i]<=k&&a[i]!=)
{
ans=(i-m)*;
break;
}
}
for(int i=;i<m;i++)
{
if(a[i]<=k&&a[i]!=)
{
ans=min(ans,(m-i)*);
}
}
printf("%d\n",ans);
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.

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

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

 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
int n,m,k;
int a[];
int x,y;
map<int,int>mp;
map<int,int>mpp;
int main()
{
scanf("%d %d %d",&n,&m,&k);
for(int i=; i<=m; i++)
{
scanf("%d",&a[i]);
mp[a[i]]=;
}
int flag=;
int now=-;
mpp[]=;
int ff=;
for(int i=; i<=k; i++)
{
scanf("%d %d",&x,&y);
if(mpp[x]==&&mpp[y]==)
continue;
else
{
if(mpp[x]==)
{
if(mp[y]==&&flag==)
{
now=y;
flag=;
}
else
{
mpp[x]=;
mpp[y]=;
ff=y;
}
}
else
{
if(mp[x]==&&flag==)
{
now=x;
flag=;
}
else
{
mpp[y]=;
mpp[x]=;
ff=x;
}
}
}
}
if(mp[]==)
{
printf("1\n");
return ;
} if(now==-)
printf("%d\n",ff);
else
printf("%d\n",now);
return ;
}
/*
7 3 4
1 4 6
1 2
2 5
5 7
7 1
*/
C. Bank Hacking
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks.

There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the banks. All banks are initially online. Each bank also has its initial strength: bank i has initial strength ai.

Let us define some keywords before we proceed. Bank i and bank j are neighboring if and only if there exists a wire directly connecting them. Bank i and bank j are semi-neighboring if and only if there exists an online bank k such that bank i and bank k are neighboring and bank k and bank j are neighboring.

When a bank is hacked, it becomes offline (and no longer online), and other banks that are neighboring or semi-neighboring to it have their strengths increased by 1.

To start his plan, Inzane will choose a bank to hack first. Indeed, the strength of such bank must not exceed the strength of his computer. After this, he will repeatedly choose some bank to hack next until all the banks are hacked, but he can continue to hack bank x if and only if all these conditions are met:

  1. Bank x is online. That is, bank x is not hacked yet.
  2. Bank x is neighboring to some offline bank.
  3. The strength of bank x is less than or equal to the strength of Inzane's computer.

Determine the minimum strength of the computer Inzane needs to hack all the banks.

Input

The first line contains one integer n (1 ≤ n ≤ 3·105) — the total number of banks.

The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the strengths of the banks.

Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — meaning that there is a wire directly connecting banks ui and vi.

It is guaranteed that the wires connect the banks in such a way that Inzane can somehow hack all the banks using a computer with appropriate strength.

Output

Print one integer — the minimum strength of the computer Inzane needs to accomplish the goal.

Examples
Input
5
1 2 3 4 5
1 2
2 3
3 4
4 5
Output
5
Input
7
38 -29 87 93 39 28 -55
1 2
2 5
3 2
2 4
1 7
7 6
Output
93
Input
5
1 2 7 6 7
1 5
5 3
3 4
2 4
Output
8
Note

In the first sample, Inzane can hack all banks using a computer with strength 5. Here is how:

  • Initially, strengths of the banks are [1, 2, 3, 4, 5].
  • He hacks bank 5, then strengths of the banks become [1, 2, 4, 5,  - ].
  • He hacks bank 4, then strengths of the banks become [1, 3, 5,  - ,  - ].
  • He hacks bank 3, then strengths of the banks become [2, 4,  - ,  - ,  - ].
  • He hacks bank 2, then strengths of the banks become [3,  - ,  - ,  - ,  - ].
  • He completes his goal by hacking bank 1.

In the second sample, Inzane can hack banks 4, 2, 3, 1, 5, 7, and 6, in this order. This way, he can hack all banks using a computer with strength 93.

题意:给你一颗树 有点权  初始选取一个点i进行hack操作  与i相连的点 点权增加1  之后选取与i相连的所有点j进行hack操作 同样与j相连的点 点权增加1(点被hack掉之后权值不再变化) 直到将n个点全部hack掉 进行hack操作 需要一个力量值大于等于当前点的点权 问最小的力量值hack掉所有的点。

题解:枚举初始hack点i   ans=min(ans,max(i的点权,max(与i相连的点的权值最大值+1,其余点的权值最大值+2)));  set 处理;

 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
int n;
ll a[];
vector<ll> mp[];
multiset<ll> s;
multiset<ll>::iterator it;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
s.insert(a[i]);
}
ll l,r;
for(int i=; i<n; i++)
{
scanf("%I64d %I64d",&l,&r);
mp[l].push_back(r);
mp[r].push_back(l);
}
ll ans=;
ll exm1=-1e9-,exm2=-1e9-;
for(int i=; i<=n; i++)
{
exm1=-1e9-;
exm2=-1e9-;
it=s.find(a[i]);
s.erase(it);
for(int j=; j<mp[i].size(); j++)
{
exm1=max(exm1,a[mp[i][j]]);
it=s.find(a[mp[i][j]]);
s.erase(it);
}
if(s.empty())
{
ans=min(ans,max(a[i],exm1+));
for(int j=; j<mp[i].size(); j++)
s.insert(a[mp[i][j]]);
s.insert(a[i]);
continue;
}
it=s.end();
it--;
exm2=*it;
ans=min(ans,max(max(a[i],exm1+),exm2+));
for(int j=; j<mp[i].size(); j++)
s.insert(a[mp[i][j]]);
s.insert(a[i]);
}
printf("%I64d\n",ans);
return ;
}

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

  1. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  2. Codeforces Round #354 (Div. 2) B. Pyramid of Glasses 模拟

    B. Pyramid of Glasses 题目连接: http://www.codeforces.com/contest/676/problem/B Description Mary has jus ...

  3. Codeforces Round #408 (Div. 2)(A.水,B,模拟)

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

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

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

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

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

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

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

  7. Codeforces Round #408 (Div. 2) B

    Description Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, n ...

  8. Codeforces Round #408 (Div. 2)

    C. Bank Hacking 题目大意:给出一棵n个节点的树,每个节点有一个权值,删掉一个点的代价为当前这个点的权值,并且会使其相邻点和距离为2且中间隔着未被删除的点的点权值加1,现在选一个点开始删 ...

  9. Codeforces Round #408 (Div. 2) 题解【ABCDE】

    A - Buying A House 题意:给你n个房间,妹子住在第m个房间,你有k块钱,你想买一个离妹子最近的房间.其中相邻的房间之间距离为10,a[i]=0表示已经被别人买了. 题解:扫一遍更新答 ...

随机推荐

  1. spark重点知识

    1 scala 2 spark rdd 3 sprak core 4 性能优化 5 spark sql 6 spark streaming 掌握程度-精通的理解:

  2. 002 -- MySQL的逻辑架构

                                            msql的逻辑架构图 第一层:主要功能是连接处理.授权认证.安全等.相当于JavaEE中的常说的Web层 第二层:包含了 ...

  3. 2.5星|《哈佛商学院管理与MBA案例全书》:书名太唬人了,依据中文经管书汇编整理而成

    哈佛商学院管理与MBA案例全书(套装十册) 看到最后,列出的参考书目中全部是中文经管书,才明白这本书不是哈佛商学院出版的,是国内的编辑做的汇编.参考书目中除了中文经管书之外,还有一套<哈佛商学院 ...

  4. [寒假学习笔记](一)Markdown语法学习

    Markdown 学习 在博客园上使用markdown编辑,记录学习进度,以来日可以复习 前期准备 1. 安装markdownpad2 官网直接找下载安装,遇到bug他会自动提示信息,跟着提示去安装一 ...

  5. 基于C#的机器学习--机器学习的基本知识

    机器学习的基本知识 ,…用n个观测值测量.但我们不再对Y的预测感兴趣,因为我们不再有Y了,我们唯一感兴趣的是在已有的特征上发现数据模式: ​ 在前面的图中,我们可以看到这样的数据本身更适合于非线性方法 ...

  6. Java中的Object类的toString()方法,equals()方法

    Object类是所有类的父类,若没有明确使用extends关键字明确表示该类继承哪个类,那么它就默认继承Object类,也就可以使用Object中的方法: 1.toString 如果输出一个对象的时候 ...

  7. 本周WEB技术学习情况

    相较于之前本周有了明显的进步    之前不熟悉的知识点在多次的实机中得到巩固加深,用得越来越得心应手 我认为只要多用功更加自主的学习  web其实并不难 希望自己天天进步

  8. OpenLayers 3 入门教程

    OpenLayers 3 入门教程摘要OpenLayers 3对OpenLayers网络地图库进行了根本的重新设计.版本2虽然被广泛使用,但从JavaScript开发的早期发展阶段开始,已日益现实出它 ...

  9. Dsyy的第一篇博文~

    2017-08-07  周一  晴热热热热热 咳咳,很多人看到dsyy第一反应是什么意思?当然是大神媛媛!显然不是些(diao)(si)yy.(da)(si)yy...的别义,咋有点此地无银三百两的感 ...

  10. 软工网络15团队作业4-DAY5

    每日例会 昨天的工作. 张陈东芳:界面排版优化 吴敏烽:界面排版优化 周汉麟:继续根据商品编号来获取商品资料方法调试 林振斌:继续输出最近浏览记录的方法调试 李智:界面排版优化 全体人员:界面优化,初 ...