1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. int cnk(int n, int k)
  7. {
  8. int a,b;
  9. a=b=;
  10. for(int i=; i<k; i++)
  11. {
  12. a *= n--;
  13. b *= (i+);
  14. }
  15.  
  16. return a/b;
  17. }
  18.  
  19. int arrange_calculate(int *a)
  20. {
  21. int n=;
  22. int ans=;
  23. for(int i=; i<; i++)
  24. n += a[i];
  25.  
  26. for(int i=; i<; i++)
  27. if(a[i]>)
  28. {
  29. ans *= cnk(n, a[i]);
  30. n -= a[i];
  31. }
  32. return ans;
  33. }
  34.  
  35. int main()
  36. {
  37. int T,N;
  38. cin>>T;
  39. for(int i=; i<T; i++)
  40. {
  41. cin>>N;
  42. int a[]={}; //记录N中1-9出现的次数
  43. int total=; //记录N的各个位上的数之和
  44. int count=; //保存N有多少位,1表示个位,2表示十位,3表示百位,以此类推
  45. while(N)
  46. {
  47. int temp = N%;
  48. total += temp;
  49. a[temp]++;
  50. N /=;
  51. count++;
  52. }
  53. int arrangeNum = arrange_calculate(a);
  54.  
  55. int s=;
  56. for(int j=; j<count; j++)
  57. {
  58. s += total;
  59. total *= ;
  60. }
  61.  
  62. int ans;
  63. if(arrangeNum<count) //此时输入的N一定是22222这种各个位上的数都相同的这种类型的数
  64. ans = s/count;
  65. else
  66. ans = (int)(s * (arrangeNum*1.0/count)); //arrangeNum不一定是count的整数倍,比如2233对应的count=4,arrangeNum=6
  67.  
  68. cout<<ans<<endl;
  69.  
  70. }
  71. return ;
  72. }

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. 许令波老师的java的IO机制分析文章

    深入分析 Java I/O 的工作机制 I/O 问题可以说是当今互联网 Web 应用中所面临的主要问题之一,因为当前在这个海量数据时代,数据在网络中随处流动.这个流动的过程中都涉及到 I/O 问题,可 ...

  2. org.springframework.web.context.ContextLoaderListener 转

    ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息.因为它实现了ServletContextListener这个接口,在web ...

  3. javascipt取整数四舍五入

    1.丢弃小数部分,保留整数部分 parseInt(5/2) 2.向上取整,有小数就整数部分加1 Math.ceil(5/2) 3,四舍五入. Math.round(5/2) 4,向下取整 Math.f ...

  4. MVC5 学习整理

    一.概述 MVC简介: •       模型(Model) “数据模型”(Model)用于封装与应用程序的业务逻辑相关的数据以及对数据的处理方法.“模型”有对数据直接访问的权力,例如对数据库的访问.“ ...

  5. XML文档部署到Tomcat服务器上总是加载出错

    config.xnl 起初文档路径是在src/Dao/config.xml 在Dao目录下BaseDao类中,解析config.xml文件路径 path="/Dao/config.xml&q ...

  6. codeforce 230D Dijsktra

    #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...

  7. poj 1011 搜索减枝

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

  8. 简单粗暴地理解 JavaScript 原型链

    尼玛!你特么也是够了! Don’t BB! Show me the code! function Person (name) { this.name = name; } function Mother ...

  9. Treasure Hunt - POJ 1066(线段相交判断)

    题目大意:在一个正方形的迷宫里有一些交错墙,墙的两端都在迷宫的边缘墙上面,现在得知迷宫的某个位置有一个宝藏,所以需要砸开墙来获取宝藏(只能砸一段墙的中点),问最少要砸开几面墙.   分析:这个题意刚开 ...

  10. for循环++i效率

    偶然用到for循环 注意查看了一下 ++i的速度更快 这是PHP语言独有的 其他语言不会有这种情况