• POJ 2664 Prerequisites?(简单题)


    【题意简述】:k:已经选择的科目数;m:选择的科目类别;c:能够选择的科目数。r:要求最少选择的科目数量

    在输入的k和m以下的一行是选择的科目号。

    比如:

    3 2                              //3是他选择了3科。2表示选择了两个类别
    0123 9876 2222                   //这是他选择的详细的3科科目的科目号
    2 1 8888 2222                    //当中2表示在这个类别里共同拥有两科8888和2222,然后最少要选择这两个中的一个
    3 2 9876 2222 7654               //这是第二个类别。含义同上。


    详细代码:

    //208K 500Ms
    #include<iostream>
    using namespace std;
    
    int k,m,c,r;
    int a[100];
    int b[100];
    
    int main()
    {
    	while(1)
    	{
    		int flag = 0;
    		cin>>k;
    		if(k == 0) break;
    		cin>>m;
    		for(int i = 0;i<k;i++)
    			cin>>a[i];
    		while(m--)
    		{
    			int count = 0;
    			cin>>c>>r;
    			for(int i = 0;i<c;i++)
    				cin>>b[i];
    			for(int i = 0;i<k;i++)
    			{
    				for(int j = 0;j<c;j++)
    				{
    					if(a[i] == b[j])
    						count++;
    				}
    			}
    			if(count < r)
    			{
    				flag = 1;
    			}
    		}
    		if(flag)
    			cout<<"no"<<endl;
    		else
    			cout<<"yes"<<endl;
    	}
    	return 0;
    }


  • 相关阅读:
    Swift 懒加载
    Swift 模型属性
    Swift 循环引用
    Two Sum
    Best Time to Buy and Sell Stock II
    Best Time to Buy and Sell Stock I
    Pascal's Triangle II
    杨辉三角(数组)
    Merge Sorted Array 合并数组
    Plus One
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/6755297.html
Copyright © 2020-2023  润新知