zoukankan      html  css  js  c++  java
  • 牛客网 Wannafly挑战赛9 A.找一找-数据处理

    好几天没好好学习了(咸鱼晒干了)

    把稍微没那么咸鱼的几天前的一场牛客网的比赛稍微看了一下,菜的要死,这一场大数的比较多,都死了。

    A.找一找

    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 262144K,其他语言524288K
    64bit IO Format: %lld

    题目描述

    给定n个正整数,请找出其中有多少个数x满足:在这n个数中存在数y=kx,其中k为大于1的整数

    输入描述:

    第一行输入一个n
    接下来一行输入n个正整数ai

    输出描述:

    输出符合条件个数
    示例1

    输入

    5
    1 2 3 4 5

    输出

    2

    说明

    5个数中1和2符合条件,1是后面每个数的因子

    这道题如果两个直接比较数组里的数for,会超时,因为数组里可能有相同的数,所以数据处理一下,直接比较一次将数的个数加起来就可以,遍历数据范围那么大小就可以了,暴力。


    代码:
     1 //A-这个题将数据压缩一下,可以减少循环次数
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<cmath>
     6 #include<algorithm>
     7 #include<queue>
     8 using namespace std;
     9 const int maxn=1e6+10;
    10 const int maxm=1e6;
    11 int num[maxn];
    12 int main(){
    13     int n;
    14     while(~scanf("%d",&n)){
    15         for(int i=0;i<n;i++){
    16             int x;
    17             scanf("%d",&x);
    18             num[x]++;
    19         }
    20         int ans=0;
    21         for(int i=1;i<=maxm;i++){
    22             if(num[i]){
    23                 for(int j=i*2;j<=maxm;j+=i){
    24                     if(num[j]){
    25                         ans+=num[i];break;
    26                     }
    27                 }
    28             }
    29         }
    30         printf("%d
    ",ans);
    31     }
    32     return 0;
    33 }



     
  • 相关阅读:
    设计模式
    WCF 4 安全性和 WIF 简介
    锁,性能调优
    javascript 异步
    javascript的回调函数
    HTML 5 简介
    CSS3 教程
    implementation of python string
    Extending Python with C or C++
    python,deep copy,shallow copy
  • 原文地址:https://www.cnblogs.com/ZERO-/p/8423389.html
Copyright © 2011-2022 走看看