USACO 3.1 Humble Numbers

以前做过类似的。卡了精度一次,2Y。

 1 /*

 2   ID: cuizhe

 3   LANG: C++

 4   TASK: humble

 5 */

 6 #include <iostream>

 7 #include <cstdio>

 8 #include <cstring>

 9 #include <cmath>

10 #include <algorithm>

11 using namespace std;

12 #define N 1000000000

13 long long prim[100011];

14 int num[101],o[101];

15 int main()

16 {

17     int i,j,k,n,temp,t;

18     freopen("humble.in","r",stdin);

19     freopen("humble.out","w",stdout);

20     scanf("%d%d",&k,&n);

21     for(i = 1;i <= k;i ++)

22     scanf("%d",&num[i]);

23     sort(prim+1,prim+k+1);

24     for(i = 1;i <= k;i ++)

25     o[i] = 1;

26     prim[1] = 1;

27     for(i = 2;i <= n+1;i ++)

28     {

29         temp = num[1]*prim[o[1]];t = 1;

30         for(j = 2;j <= k;j ++)

31         {

32             if(temp > num[j]*prim[o[j]])

33             {

34                 temp = num[j]*prim[o[j]];

35                 t = j;

36             }

37         }

38         prim[i] = temp;

39         if(prim[i] == prim[i-1])

40         i --;

41         o[t]++;

42     }

43     printf("%lld\n",prim[n+1]);

44     return 0;

45 }

你可能感兴趣的:(number)