zoukankan      html  css  js  c++  java
  • P1414 又是毕业季(数论)

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 using namespace std;
     5 const int N=1e6+10;
     6 int c[N];
     7 int main()
     8 {
     9     int n;
    10     cin>>n;
    11     int m=0;
    12     for(int i=1;i<=n;i++)
    13     {
    14         int x;
    15         cin>>x;
    16         m=max(m,x);//记录最大
    17         for(int j=1;j*j<=x;j++)
    18         {
    19             if(x%j==0)
    20             {
    21                 c[j]++;
    22                 if(j*j!=x)//一下两个
    23                 {
    24                     c[x/j]++;
    25                 }
    26             }
    27         }
    28     }
    29     int p=m;//默契值
    30     for(int i=1;i<=n;i++)//人数
    31     {
    32         while(c[p]<i)
    33         {
    34             p--;
    35         }
    36         cout<<p<<endl;
    37     }
    38     return 0;
    39 }

    具体思想就是求因数,然后统计。

    先是把有这个因数的数有多少个统计出来,比如说样例1 2 3 4 ,那么因数1就有4个,2就有2个,3就有1个,4就有1个,所以人数1234的最大默契值分别是4 2 1 1

    至于后面怎么统计就是从默契值大往小枚举,如果符合条件则输出。

  • 相关阅读:
    数据结构上机思考
    hdu1005,循环节
    网络赛总结
    icpc沈阳网络赛。cake cake!
    树的基础代码
    网络赛第一场
    欧拉函数
    欧拉函数
    多校第十场
    (环上)最大子段和
  • 原文地址:https://www.cnblogs.com/greenofyu/p/12200515.html
Copyright © 2011-2022 走看看