UVa11076 - Add Again

简介: UVa11076 - Add Again
#include <cstdio>#include <cstring>usingnamespacestd;
typedeflonglongLL;
constintN=10;
intcnt[N];
intn;
LLfactorial(intx);
LLf(intx);
voidsolve();
boolinput();
intmain()
{
#ifndef ONLINE_JUDGEfreopen("e:\\uva_in.txt", "r", stdin);
#endifwhile (input()) {
solve();
    }
return0;
}
boolinput()
{
if (scanf("%d", &n) !=1||n==0) returnfalse;
memset(cnt, 0x00, sizeof(cnt));
for (inti=0; i<n; i++) {
intx;
scanf("%d", &x);
cnt[x]++;
    }
returntrue;
}
LLfactorial(intx)
{
if (x==0||x==1) return1LL;
elsereturn (LL)x*factorial(x-1);
}
LLf(intx)
{
LLans=0;
for (inti=0; i<n; i++) {
ans=ans*10+x;
    }
returnans;
}
voidsolve()
{
LLnum=factorial(n);
for (inti=0; i<N; i++) {
if (cnt[i] !=0) {
num/=factorial(cnt[i]);
        }
    }
LLans=0;
for (inti=0; i<N; i++) {
if (cnt[i] !=0) {
ans+=f(i) *num*cnt[i] /n;
        }
    }
printf("%lld\n", ans);
}
目录
相关文章
|
7月前
|
算法
uva 10891 game of sum
题目链接 详细请参考刘汝佳《算法竞赛入门经典训练指南》 p67
15 0
|
9月前
UVa343 What Base Is This
UVa343 What Base Is This
34 0
|
9月前
uva127 "Accordian" Patience
uva127 "Accordian" Patience
25 0
|
11月前
|
存储 算法 安全
LeetCode - #2 Add Two Numbers
我们社区从本期开始会将顾毅(Netflix 增长黑客,《iOS 面试之道》作者,ACE 职业健身教练。)的 Swift 算法题题解整理为文字版以方便大家学习与阅读。 不积跬步,无以至千里;不积小流,无以成江海,Swift社区 伴你前行。
LeetCode - #2 Add Two Numbers
|
算法 Python 容器
leetcode 2 Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit.
978 0
LeetCode - 2. Add Two Numbers
2. Add Two Numbers  Problem's Link  ---------------------------------------------------------------------------- Mean:  给你两个数字链表,让你将两个链表相加,结果保存在一个新链表中.
919 0