#include<iostream>
#include<vector>
#include<algorithm>
using namespace std; int cnk(int n, int k)
{
int a,b;
a=b=;
for(int i=; i<k; i++)
{
a *= n--;
b *= (i+);
} return a/b;
} int arrange_calculate(int *a)
{
int n=;
int ans=;
for(int i=; i<; i++)
n += a[i]; for(int i=; i<; i++)
if(a[i]>)
{
ans *= cnk(n, a[i]);
n -= a[i];
}
return ans;
} int main()
{
int T,N;
cin>>T;
for(int i=; i<T; i++)
{
cin>>N;
int a[]={}; //记录N中1-9出现的次数
int total=; //记录N的各个位上的数之和
int count=; //保存N有多少位,1表示个位,2表示十位,3表示百位,以此类推
while(N)
{
int temp = N%;
total += temp;
a[temp]++;
N /=;
count++;
}
int arrangeNum = arrange_calculate(a); int s=;
for(int j=; j<count; j++)
{
s += total;
total *= ;
} int ans;
if(arrangeNum<count) //此时输入的N一定是22222这种各个位上的数都相同的这种类型的数
ans = s/count;
else
ans = (int)(s * (arrangeNum*1.0/count)); //arrangeNum不一定是count的整数倍,比如2233对应的count=4,arrangeNum=6 cout<<ans<<endl; }
return ;
}

Problem 1183 - 排列的更多相关文章

  1. UVALive 6909 Kevin's Problem 数学排列组合

    Kevin's Problem 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid ...

  2. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合

    E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...

  3. 九度OJ 1183 守形数 (模拟)

    题目1183:守形数 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2663 解决:1424 题目描写叙述: 守形数是这样一种整数.它的平方的低位部分等于它本身. 比方25的平方是625. ...

  4. 九度OJ 1183:守形数 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3815 解决:2005 题目描述: 守形数是这样一种整数,它的平方的低位部分等于它本身. 比如25的平方是625,低位部分是25,因此25是 ...

  5. [codevs 1183][泥泞的道路(二分+spfa)

    题目:http://dev.codevs.cn/problem/1183/ 分析:这个和最优比率生成树很像,都可以二分答案的,只不过判定方面一个是求是否有最短路径,一个是求是否有生成树.假设等待判定的 ...

  6. lintcode Permutation Index

    题目:http://www.lintcode.com/zh-cn/problem/permutation-index/ 排列序号 给出一个不含重复数字的排列,求这些数字的所有排列按字典序排序后该排列的 ...

  7. 【Codevs1183】泥泞的道路

    Position: http://codevs.cn/problem/1183/ List Codevs1183 泥泞的道路 List Description Input Output Sample ...

  8. ACDream - Xor pairs

    先上题目: Xor pairs Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Sub ...

  9. Codeforcs 1183B Equalize Prices

    题目链接:codeforces.com/problemset/problem/1183/B 题意:给你 n 个数,每个数能在k范围内上下浮动,求能否使所有数相等,能输出相等的最大值,不能输出 -1. ...

随机推荐

  1. Linux下高效编写Shell——shell特殊字符汇总

    Linux下无论如何都是要用到shell命令的,在Shell的实际使用中,有编程经验的很容易上手,但稍微有难度的是shell里面的那些个符号,各种特殊的符号在我们编写Shell脚本的时候如果能够用的好 ...

  2. JavaScript高级程序设计14.pdf

    继承,ECMAScript只支持实现继承,而且其实现继承主要是依靠原型链来实现的 构造函数.原型.和实例的关系:每个构造函数都有一个原型对象,每个原型对象都包含一个指向构造函数的指针,每个实例都包含一 ...

  3. Bzoj 2588: Spoj 10628. Count on a tree 主席树,离散化,可持久,倍增LCA

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2588 2588: Spoj 10628. Count on a tree Time Limit ...

  4. poj 2449 第k短路

    题目链接:http://poj.org/problem?id=2449 #include<cstdio> #include<cstring> #include<iostr ...

  5. Ehcache专栏

    http://www.iteye.com/blogs/subjects/ehcache

  6. UVa1628 UVaLive5847 Pizza Delivery

    填坑系列(p.302) 既然不知道后面还要卖多少个就加一维状态嘛.. lrj写的O(n)转移?其实转移可以O(1) 貌似按x排序有奇效? #include<cstdio> #include ...

  7. FZU 2104 (13.11.28)

    Problem 2104 Floor problem Accept: 376    Submit: 433 Time Limit: 1000 mSec    Memory Limit : 32768 ...

  8. 使用PullToRefresh实现下拉刷新和上拉加载

    使用PullToRefresh实现下拉刷新和上拉加载 分类: Android2013-12-20 15:51 78158人阅读 评论(91) 收藏 举报 Android下拉刷新上拉加载PullToRe ...

  9. shell之“>/dev/null 2>&1” 详解(转)

    今天在自己的一个技术群中又被问道了这么一个问题,于是又通俗的解释了一下,做个记录,大家看看解释是否清楚! shell中可能经常能看到:>/dev/null 2>&1 命令的结果可以 ...

  10. android 43 SQLite数据库

    SQLite数据库很小,占用内存只有几百K,安卓和IOS都是用的SQLite数据库. 页面: <LinearLayout xmlns:android="http://schemas.a ...