zoukankan      html  css  js  c++  java
  • codevs 1553 互斥的数

     时间限制: 1 s
     空间限制: 128000 KB
     题目等级 : 黄金 Gold
     
     
     
    题目描述 Description

    有这样的一个集合,集合中的元素个数由给定的N决定,集合的元素为N个不同的正整数,一旦集合中的两个数x,y满足y = P*x,那么就认为x,y这两个数是互斥的,现在想知道给定的一个集合的最大子集满足两两之间不互斥。

    输入描述 Input Description

    输入有多组数据,每组第一行给定两个数N和P(1<=N<=10^5, 1<=P<=10^9)。接下来一行包含N个不同正整数ai(1<=ai<=10^9)。

    输出描述 Output Description

    输出一行表示最大的满足要求的子集的元素个数。

    样例输入 Sample Input

    4 2

    1 2 3 4

    样例输出 Sample Output

    3

    #include<algorithm>
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<map>
    using namespace std;
    map<int,int>ma;
    int n,p,s,ans;
    int a[1000000]; 
    bool cmp(int x,int y)
    {
        return x>y;
    }
    int main()
    {
        cin>>n>>p;
        for(int i=1;i<=n;i++)    cin>>a[i],ma[a[i]]=0;
        sort(a+1,a+n+1);
        for(int i=1;i<=n;i++)
        if(!ma[a[i]]) ma[a[i]*p]=1,ans++;
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    Windbg DUMP
    NET媒体文件操作组件TagLib
    NET Framework、.NET Core、Xamarin
    面向切面编程
    微服务
    NET Core
    Yeoman generator
    Service Fabric
    Vue.JS 2.x
    CoreCLR
  • 原文地址:https://www.cnblogs.com/chen74123/p/6729522.html
Copyright © 2011-2022 走看看