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

    有这样的一个集合,集合中的元素个数由给定的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

     1 #include <algorithm>
     2 #include <cstdio>
     3 #include <map>
     4 
     5 using namespace std;
     6 
     7 map<int,bool>ma;
     8 int n,p,a[1000005],ans;
     9 
    10 int main()
    11 {
    12     scanf("%d%d",&n,&p);
    13     for(int i=1;i<=n;i++)
    14         scanf("%d",&a[i]),ma[a[i]]=0;
    15     sort(a+1,a+n+1);
    16     for(int i=1;i<=n;i++)
    17         if(!ma[a[i]])
    18         {
    19             ma[a[i]*p]=1;
    20             ans++;
    21         }
    22     printf("%d",ans);
    23     return 0;
    24 }
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    RedMine 1.3.3 安装攻略
    .net 4.0 framework 安装时发生严重错误
    MYSQL安装配置
    接口隔离ISP
    依赖倒置DIP
    VS2010添加WP模板
    VS2012尝鲜
    OCP开放闭合
    单一职责
    里氏替换
  • 原文地址:https://www.cnblogs.com/Shy-key/p/6375821.html
Copyright © 2011-2022 走看看