zoukankan      html  css  js  c++  java
  • POJ 2664

    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #define MAXN 105
    using namespace std;
    
    int a[MAXN];
    bool Binarry_search(int a[],int size,int num);
    
    bool binarry_search(int a[],int num,int low,int high);
    int main()
    {
        //freopen("acm.acm","r",stdin);
        int cous;
        int cate;
        int c;
        int r;
        int i;
        int j;
        int tem;
        int test;
        bool boo;
        while(scanf("%d%d",&cous,&cate),cous)
        {
        boo = false;
        test = 0;
        for(i = 0; i < cous; ++ i)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+cous);
        for(i = 0;i < cate; ++ i)
        {
            scanf("%d%d",&c,&r);
            for(j = 0; j < c; ++ j)
            {
                scanf("%d",&tem);
                if(binarry_search(a,tem,0,cous-1))
                    ++ test;
            }
            if(test < r)
            {
                boo = true;
            }
            test = 0;
        }
        if(!boo)
            cout<<"yes"<<endl;
        else
            cout<<"no"<<endl;
        }
    }
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    //·                                              Binarry_search_algorithm            ·//
    ////////////////////////////////////////////////////////////////////////////////////////
    bool Binarry_search(int a[],int size,int num)
    {
        int i;
        int low = 0;
        int high = size -1;
        int mid;
        while(low <= high)
        {
            mid = (low + high)/2;
            if(num < a[mid])
            {
                high = mid - 1;
            }
            else if(num > a[mid])
            {
                low = mid + 1;
            }
            else 
                return true;
        }    
        return false;
    }
    
    
    bool binarry_search(int a[],int num,int low,int high)
    {
        int mid;
        mid = (low + high)/2;
        if(low > high)
            return false;
        if(num < a[mid])
            binarry_search(a,num,low,mid - 1);
        else if(num > a[mid])
            binarry_search(a,num,mid + 1,high);
        else
            return true;
        
    }
  • 相关阅读:
    Idea中资源文件的设置和Java中类的权限
    Springboot中slf4j+log4j2的使用
    linux下修改文件查看样式(日期/文件大小)
    maven项目中引入外部jar
    01背包问题
    python爬取千千音乐
    【DataBase】SQL优化案例:其一
    【Uni-App】底部栏踩坑
    【Uni-App】UniApp转微信小程序发布应用
    【Uni-App】API笔记 P2
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4568635.html
Copyright © 2011-2022 走看看