zoukankan      html  css  js  c++  java
  • 排列之和 (Add Again,UVa 11076)

     1 #include <iostream>
     2 #include <string.h>
     3 #include <string>
     4 #include <fstream>
     5 #include <algorithm>
     6 #include <stdio.h>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 using namespace std;
    12 const double eps = 1e-8;
    13 const int INF=0x7fffffff;
    14 unsigned long long uINF = ~0LL;
    15 #define MAXN 10000007
    16 typedef unsigned long long LL;
    17 LL vis[MAXN];
    18 LL prime[MAXN];
    19 
    20 void sieve(LL n)
    21 {
    22     LL m=(LL)sqrt(n+0.5);
    23     memset(vis,0,sizeof(vis));
    24     for(LL i=2;i<=m;i++)if(!vis[i])
    25     for(LL j=i*i;j<=n;j+=i)vis[j]=1;
    26 }
    27 
    28 LL gen_prime(LL n)
    29 {
    30     sieve(n);
    31     LL c=0;
    32     for(LL i=2;i<=n;i++)if(!vis[i])
    33         prime[c++]=i;
    34     return c;
    35 }
    36 
    37 LL gcd(LL a,LL b)
    38 {
    39     return b==0?a:gcd(b,a%b);
    40 }
    41 
    42 int main()
    43 {
    44     int N;
    45     int a[13];a[0]=1;
    46     for(int i=1;i<13;i++){a[i]=a[i-1]*i;}
    47 
    48     LL num[12];
    49     while(scanf("%d",&N),N)
    50     {
    51         int hash[11];
    52         LL t=0;
    53         memset(hash,0,sizeof(hash));
    54         for(int i=0;i<N;i++)
    55         {
    56         scanf("%lld",&num[i]);
    57         hash[num[i]]++;
    58         t=t*10+1;
    59         }
    60         LL ans=0;
    61         LL sum=0;
    62             int temp=a[N];
    63             for(int i=0;i<N;i++){sum+=num[i];}
    64             for(int i=0;i<10;i++)temp/=a[hash[i]];
    65             ans+=sum*t*temp/N;
    66             printf("%lld
    ",ans);
    67     }
    68 
    69     return 0;
    70 }

    卡在计算 排列的个数上了好久……=。=

  • 相关阅读:
    基于maven构建javaweb项目思路梳理及改进 在路上
    分圆多项式整理
    第03次作业栈和队列
    C语言第二次实验报告
    week01绪论作业
    第02次作业线性表
    C语言第一次实验报告
    工作流的问题
    无法使用Outlook 2003 Out Of Office Assisant
    刷机
  • 原文地址:https://www.cnblogs.com/TO-Asia/p/3204915.html
Copyright © 2011-2022 走看看