贝壳找房(计蒜客)

现在有许多房源,于是贝壳找房为每个房子都设置了一个等级,从郊区到市区依次排开(这些房子都是连续的),凑巧的是这些房子的等级正好满足数列:

 

\displaystyle a_{i + 1} = a_i + i + 2,\ \ \ \ a_1 = 1ai+1=ai+i+2,    a1=1

 

现在有许多客户来贝壳找房找房源,他们需要一段连续的房子,按照贝壳找房的等级划分,给出了每个房子的等级要求(有序)。

输入格式

第一行输入一个整数 n (n \le 50)n(n50) 表示客户的数量。

接下来有 nn 行输入,每行的第一个整数 m (1 \le m \le 10^4)m(1m104) 表示用户需要的房子数目,后面有 mm 个整数 a_i (1 \le a_i \le 10^9)ai(1ai109) , 表示房子的等级要求。

输出格式

对于每个客户的需求输出是否有房源可以满足(不需要考虑前面的客户是否买过),如果可以满足输出"yes",否则输出"no"

样例输入

2
3 1 4 8
3 4 8 10

样例输出

yes
no
解题思路:我是真的菜。。。。。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>

using namespace std;

map<int,int> flag;

int main(){
    int n,m;
    int a[10005];
    long long a1=1;
    flag[1]=1;
    for(int i=2;i<=40000;i++){
        a1+=(i-1)+2;
        flag[a1]=1;
    }

    scanf("%d",&n);
    while(n--){
        int f=1;
        scanf("%d",&m);
        for(int i=0;i<m;i++){
            scanf("%d",&a[i]);
            if(flag[a[i]]!=1){
                f=0;
            }
        }
        if(f==1){
            printf("yes\n");
            continue;
        }else{
            printf("no\n");
            continue;
        }
    }

}

 

posted @ 2018-05-27 14:22  多一份不为什么的坚持  阅读(710)  评论(0编辑  收藏  举报