UVA 11076 Add Again——计数原理
注意先乘后除否则会有精度损失
#include #include #include #include #define OUT freopen("out.txt", "w", stdout)using namespace std;typedef long long ll;const int maxn = 15;const ll one[] = {0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111, 11111111111, 111111111111};ll n, a[maxn];ll cnt, val[maxn], num[maxn], sum;int main() { //OUT; while (~scanf("%lld", &n) && n) { sum = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); sum += a[i]; } sort(a + 1, a + 1 + n); memset(num, 0, sizeof(num)); val[1] = a[1]; num[1] = 1; cnt = 1; for (int i = 2; i <= n; i++) { if (a[i] != a[i - 1]) ++cnt; val[cnt] = a[i]; num[cnt]++; } ll n1 = 1, n2 = 1; for (int i = 1; i <= n; i++) n1 *= i; for (int i = 1; i <= cnt; i++) { for (int j = 1; j <= num[i]; j++) n2 *= j; } ll k = n1 / n2; ll ans = sum * k / n * one[n]; printf("%lld\n", ans); } return 0;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~