Codeforces Round #408 (Div. 2)(A.水,B,模拟)
A. Buying A House
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.
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 20
0 27 32 21 19
40
7 3 50
62 0 0 0 99 33 22
30
10 5 100
1 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 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代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n,m,k; 6 int a[105]; 7 while(scanf("%d%d%d",&n,&m,&k)!=EOF) 8 { 9 for(int i=1;i<=n;i++) 10 scanf("%d",&a[i]); 11 int minn=1e+6; 12 for(int i=1;i<=n;i++) 13 { 14 if(a[i]!=0&&k>=a[i]) 15 { 16 minn=min(minn,abs(m-i)*10); 17 } 18 } 19 printf("%d\n",minn); 20 } 21 return 0; 22 }
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.
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.
Print one integer — the final position along the x-axis of the bone.
7 3 4
3 4 6
1 2
2 5
5 7
7 1
1
5 1 2
2
1 2
2 4
2
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代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[1000005]; 4 int main() 5 { 6 int n,m,k,x,y,t; 7 while(scanf("%d%d%d",&n,&m,&k)!=EOF) 8 { 9 for(int i=1;i<=m;i++) 10 { 11 scanf("%d",&t); 12 a[t]=1; 13 } 14 int ans=1; 15 for(int i=1;i<=k;i++) 16 { 17 scanf("%d%d",&x,&y); 18 if(a[ans]==1) 19 continue; 20 if(ans==x) 21 ans=y; 22 else if(ans==y) 23 ans=x; 24 } 25 printf("%d\n",ans); 26 } 27 return 0; 28 }
作 者:Angel_Kitty
出 处:https://www.cnblogs.com/ECJTUACM-873284962/
关于作者:阿里云ACE,目前主要研究方向是Web安全漏洞以及反序列化。如有问题或建议,请多多赐教!
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信我
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是作者坚持原创和持续写作的最大动力!
欢迎大家关注我的微信公众号IT老实人(IThonest),如果您觉得文章对您有很大的帮助,您可以考虑赏博主一杯咖啡以资鼓励,您的肯定将是我最大的动力。thx.
我的公众号是IT老实人(IThonest),一个有故事的公众号,欢迎大家来这里讨论,共同进步,不断学习才能不断进步。扫下面的二维码或者收藏下面的二维码关注吧(长按下面的二维码图片、并选择识别图中的二维码),个人QQ和微信的二维码也已给出,扫描下面👇的二维码一起来讨论吧!!!
欢迎大家关注我的Github,一些文章的备份和平常做的一些项目会存放在这里。