zoukankan      html  css  js  c++  java
  • 贝壳找房(计蒜客)

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

    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
    ");
                continue;
            }else{
                printf("no
    ");
                continue;
            }
        }
    
    }
  • 相关阅读:
    微博个人中心效果
    微博弹性按钮
    ios9 3dtouch 博客
    去掉导航栏阴影
    模态全屏模式,实现半透明效果
    剪切图片
    修改push动画的方向
    数据库链接池终于搞对了,直接从100ms到3ms
    如何在Java代码中去掉烦人的“!=null”
    面试官:请讲下接口具体怎么优化!
  • 原文地址:https://www.cnblogs.com/TWS-YIFEI/p/9095980.html
Copyright © 2011-2022 走看看