Problem 1183 - 排列
- #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 - 排列的更多相关文章
- UVALive 6909 Kevin's Problem 数学排列组合
Kevin's Problem 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid ...
- 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 ...
- 九度OJ 1183 守形数 (模拟)
题目1183:守形数 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2663 解决:1424 题目描写叙述: 守形数是这样一种整数.它的平方的低位部分等于它本身. 比方25的平方是625. ...
- 九度OJ 1183:守形数 (数字特性)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3815 解决:2005 题目描述: 守形数是这样一种整数,它的平方的低位部分等于它本身. 比如25的平方是625,低位部分是25,因此25是 ...
- [codevs 1183][泥泞的道路(二分+spfa)
题目:http://dev.codevs.cn/problem/1183/ 分析:这个和最优比率生成树很像,都可以二分答案的,只不过判定方面一个是求是否有最短路径,一个是求是否有生成树.假设等待判定的 ...
- lintcode Permutation Index
题目:http://www.lintcode.com/zh-cn/problem/permutation-index/ 排列序号 给出一个不含重复数字的排列,求这些数字的所有排列按字典序排序后该排列的 ...
- 【Codevs1183】泥泞的道路
Position: http://codevs.cn/problem/1183/ List Codevs1183 泥泞的道路 List Description Input Output Sample ...
- ACDream - Xor pairs
先上题目: Xor pairs Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Sub ...
- Codeforcs 1183B Equalize Prices
题目链接:codeforces.com/problemset/problem/1183/B 题意:给你 n 个数,每个数能在k范围内上下浮动,求能否使所有数相等,能输出相等的最大值,不能输出 -1. ...
随机推荐
- 许令波老师的java的IO机制分析文章
深入分析 Java I/O 的工作机制 I/O 问题可以说是当今互联网 Web 应用中所面临的主要问题之一,因为当前在这个海量数据时代,数据在网络中随处流动.这个流动的过程中都涉及到 I/O 问题,可 ...
- org.springframework.web.context.ContextLoaderListener 转
ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息.因为它实现了ServletContextListener这个接口,在web ...
- javascipt取整数四舍五入
1.丢弃小数部分,保留整数部分 parseInt(5/2) 2.向上取整,有小数就整数部分加1 Math.ceil(5/2) 3,四舍五入. Math.round(5/2) 4,向下取整 Math.f ...
- MVC5 学习整理
一.概述 MVC简介: • 模型(Model) “数据模型”(Model)用于封装与应用程序的业务逻辑相关的数据以及对数据的处理方法.“模型”有对数据直接访问的权力,例如对数据库的访问.“ ...
- XML文档部署到Tomcat服务器上总是加载出错
config.xnl 起初文档路径是在src/Dao/config.xml 在Dao目录下BaseDao类中,解析config.xml文件路径 path="/Dao/config.xml&q ...
- codeforce 230D Dijsktra
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...
- poj 1011 搜索减枝
题目链接:http://poj.org/problem?id=1011 #include<cstdio> #include<cstring> #include<algor ...
- 简单粗暴地理解 JavaScript 原型链
尼玛!你特么也是够了! Don’t BB! Show me the code! function Person (name) { this.name = name; } function Mother ...
- Treasure Hunt - POJ 1066(线段相交判断)
题目大意:在一个正方形的迷宫里有一些交错墙,墙的两端都在迷宫的边缘墙上面,现在得知迷宫的某个位置有一个宝藏,所以需要砸开墙来获取宝藏(只能砸一段墙的中点),问最少要砸开几面墙. 分析:这个题意刚开 ...
- for循环++i效率
偶然用到for循环 注意查看了一下 ++i的速度更快 这是PHP语言独有的 其他语言不会有这种情况