CF A. Dreamoon and Ranking Collection 【模拟】

A. Dreamoon and Ranking Collection
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Dreamoon is a big fan of the Codeforces contests.

One day, he claimed that he will collect all the places from 11 to 5454 after two more rated contests. It's amazing!

Based on this, you come up with the following problem:

There is a person who participated in nn Codeforces rounds. His place in the first round is a1a1, his place in the second round is a2a2, ..., his place in the nn-th round is anan.

You are given a positive non-zero integer xx.

Please, find the largest vv such that this person can collect all the places from 11 to vv after xx more rated contests.

In other words, you need to find the largest vv, such that it is possible, that after xx more rated contests, for each 1iv1≤i≤v, there will exist a contest where this person took the ii-th place.

For example, if n=6n=6, x=2x=2 and a=[3,1,1,5,7,10]a=[3,1,1,5,7,10] then answer is v=5v=5, because if on the next two contest he will take places 22 and 44, then he will collect all places from 11 to 55, so it is possible to get v=5v=5.

Input

The first line contains an integer tt (1t51≤t≤5) denoting the number of test cases in the input.

Each test case contains two lines. The first line contains two integers n,xn,x (1n,x1001≤n,x≤100). The second line contains nn positive non-zero integers a1,a2,,ana1,a2,…,an (1ai1001≤ai≤100).

Output

For each test case print one line containing the largest vv, such that it is possible that after xx other contests, for each 1iv1≤i≤v, there will exist a contest where this person took the ii-th place.

扫描二维码关注公众号,回复: 10494562 查看本文章
Example
input
Copy
5
6 2
3 1 1 5 7 10
1 100
100
11 1
1 1 1 1 1 1 1 1 1 1 1
1 1
1
4 57
80 60 40 20
output
Copy
5
101
2
2
60
Note

The first test case is described in the statement.

In the second test case, the person has one hundred future contests, so he can take place 1,2,,991,2,…,99 and place 101101 on them in some order, to collect places 1,2,,1011,2,…,101

放上翻译

A、 Dreamoon和Ranking系列
每次测试的时间限制1秒
每个测试的内存限制256兆字节
输入标准输入
输出标准输出
Dreamoon是Codeforces竞赛的忠实粉丝。
 
有一天,他声称,他将收集所有的地方,从1至54后,再两个评分比赛。太神奇了!
 
基于此,您会发现以下问题:
 
有一个人参加了n个联合部队回合。他在第一轮中的位置是a1,在第二轮中的位置是a2,……他在第n轮中的位置是A。
 
给你一个正的非零整数x。
 
请找出最大的v,这样这个人就可以收集所有的地方,从1到v后,x更多的评分比赛。
 
换言之,你需要找到最大的v,这样就有可能,在x个评分更高的比赛之后,对于每一个1≤i≤v,就有一个比赛,这个人占据了i-th的位置。
 
例如,如果n=6,x=2和a=[3,1,1,5,7,10]那么答案是v=5,因为如果在接下来的两个比赛中他将获得2和4的位置,那么他将收集1到5的所有位置,所以有可能得到v=5。
 
输入
第一行包含一个整数t(1≤t≤5),表示输入中的测试用例数。
 
每个测试用例包含两行。第一行包含两个整数n,x(1≤n,x≤100)。第二行包含n个正的非零整数a1、a2、…、an(1≤ai≤100)。
 
输出
对于每个测试用例,打印包含最大v的一行,以便在x个其他竞赛之后,对于每个1≤i≤v,将存在一个该人占据第i位的竞赛。
 
例子
输入复制
5个
6 2个
3 1 5 7 10
1100个
100个
11个1
1 1 1 1 1 1 1 1 1 1 1 1 1
11个
1个
457个
80 60 40 20个
输出拷贝
5个
101个
2个
2个
60个
注意
语句中描述了第一个测试用例。
 
在第二个测试用例中,这个人有100个未来的比赛,所以他可以在1,2,…,99和101的位置上按一定顺序进行,以收集1,2,…,101的位置。

 清明祭祖了只好今天补题】

这题的意思...我想了了好半天没理解...

其实是这样的,它每组测试数据给出个数n和可以加上的次数x,然后给n个数字想知道它最大连续可以连续到哪个数,【从1开始少了哪个就补上,最多补x次

知道这个题的意思后,这个题就变得可爱了,就可以把这n个数储存在一个数组里,然后遍历一次,若出现空缺就补上然后X--;当X==0【就次数用完了后】跳出来,再遍历一次找到最后一个连续着且不是0的【就找到啦^^

 1 #include <bits/stdc++.h>
 2 #define ll longlong
 3 using namespace std;
 4 int a[1002];//开数组不能心疼空间不然debug会死 
 5 int main(){
 6      int t;
 7      cin>>t;
 8 while(t--){
 9     int n,x;
10     cin>>n>>x;
11     //设置0很重要.....【惨痛教训 
12     memset(a,0,sizeof(a));//数组置0 
13     for(int i=0;i<n;i++){
14         int m;
15         cin>>m;
16         a[m]=1;//设置这一个位置是否出现过 
17     }
18     int j=1;
19     while(1){
20         if(a[j]==0){//当这个位置没有出现,但我还有剩余x去补的时候 
21             x--;//x的次数减少一次 
22             a[j]=1;//这个位置补好了 
23         }
24         if(x<=0)break;//x次数没有了,跳出循环; 
25         j++;
26     }
27     /*for(int i=0;i<100;i++)cout<<a[i]<<' ';//自己用来debug的 
28     cout<<'\n';
29     */    
30     int flag=0;
31     for(int i=1;i<=1002;i++){//遍历一遍看从哪个地方不可以的 
32         if(a[i]==0){//当这个位置为0的时候说明到这截至了 
33             flag=i-1;//减1是因为最后一个位置是为0的前一位 
34             break;
35         }
36     }
37     cout<<flag<<'\n';//输出 
38 }
39 return 0;
40 }

猜你喜欢

转载自www.cnblogs.com/ahijing/p/12636189.html