zoukankan      html  css  js  c++  java
  • CodeForces 1330A

    Dreamoon is a big fan of the Codeforces contests.

    One day, he claimed that he will collect all the places from 1 to 54 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 n Codeforces rounds. His place in the first round is a1, his place in the second round is a2, …, his place in the n-th round is an.

    You are given a positive non-zero integer x.

    Please, find the largest v such that this person can collect all the places from 1 to v after x more rated contests.

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

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

    Input

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

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

    Output

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

    Example Input

    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

    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,…,99 and place 101 on them in some order, to collect places 1,2,…,101.

    翻译
    Dreamoon是Codeforces竞赛的忠实拥护者。

    有一天,他声称自己将在两次额外的比赛之后从1到54收集所有名额。太奇妙了!

    基于此,您遇到以下问题:

    有人参加了n次Codeforce巡回赛。他在第一轮的位置是a1,在第二轮的位置是a2,…,在第n轮中的位置是an。

    您会得到一个非零的正整数x。

    请找到最大的v,以便此人可以在进行x次以上的比赛之后收集从1到v的所有位置。

    换句话说,您需要找到最大的v,以便在经过x次以上的竞赛之后,对于每个1≤i≤v,都有可能出现一个比赛,此人将第i位。

    例如,如果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位。

    题目大意:
    输入 t 表示 t 组测试样例,对于每组测试样例,输入 n 和 x , 表示已经获得的名次和可操作的次数,要输出最大的v ,表示在v场比赛后,再进行x场,就可以收集1-v的所有名次。
    解题思路:
    定义bool数组来存放第 i 个名次是否已经获得,一边输入一边修改bool数组,然后遍历1 - 210 (n和x都是100,所以有可能200名)如果有没获得的名次就sum++,如果sum>x,退出循环,当前的v最大。AC代码:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    const int N = 210;
    bool book[N];
    int main()
    {
    	ios::sync_with_stdio(false);
    	int t;
    	cin>>t;
    	while(t--)
    	{
    		memset(book,false,sizeof book);
    		int x,v;
    		cin>>x>>v;
    		for(int i=0;i<x;i++)
    		{
    			int a;
    			cin>>a;
    			book[a]=true;
    		}
    		int ans=-1,sum=0;
    		for(int i=1;i<=N;i++)
    		{
    			if(!book[i])
    			    sum++;
    			if(sum==v)
    			  	ans=i;
                if(sum>v)
                  break;      
    		}
    		cout<<ans<<endl;
    	}
    	//system("pause");
    	return 0;
    }
    
  • 相关阅读:
    旅行,写作,编程
    Limu:JavaScript的那些书
    怎样花两年时间去面试一个人
    IE6之各种不适记录
    19位编程大师集锦
    开源中最好的Web开发资源汇总
    流行Linux和Windows脚本语言列表
    近来,一组名为“全球郁闷青年写真”的照片在网上热传...
    浏览器端技术体系概览 前端开发的七种武器
    这个世界从来没有任何一件工作叫“钱多、事少、离家近”
  • 原文地址:https://www.cnblogs.com/Hayasaka/p/14294267.html
Copyright © 2011-2022 走看看