【题目链接】:http://codeforces.com/contest/515/problem/C

【题意】



定义f(n)=n这个数各个位置上的数的阶乘的乘积;

给你a;

让你另外求一个不含0和1的最大的数字b;

使得f(a)==f(b)

【题解】



对a的每一个大于1的数字进行分解;

看看它能够组合成的最多的比它小的数字的阶乘的乘积是哪些;

比如

4!=3!∗(2!)2

每个都找最多数目的;数目相同找大的数的组合;

求出2..9!的组合就好;

最后根据每个数字的分解方案;

求出所有的数字;

然后降序排;

顺序输出就好;



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 12; LL fac[N];
vector<int> fenjie[N];
int a[N],ans[N];
int n,temp[20],final_ans[200],num=0;
char s[20]; void dfs(int x, int pos,int num,LL now)
{
if (x > 9)
{
if (now == fac[pos])
{
if (num > ans[pos])
{
ans[pos] = num;
fenjie[pos].clear();
rep1(i, 2, 9)
{
int len = a[i];
rep1(j, 1, len)
fenjie[pos].ps(i);
}
}
}
return;
}
LL temp = 1;
int tot = 0;
while (1LL * temp*fac[x] <= fac[pos])
{
tot++;
temp = 1LL * temp*fac[x];
}
rep2(i, tot, 0)
{
if (now*temp <= fac[pos])
{
a[x] = i;
dfs(x + 1, pos, num + i, now*temp);
a[x] = 0;
}
temp /= fac[x];
}
} bool cmp(int a, int b)
{
return a > b;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
fac[0] = fac[1] = 1;
rep1(i, 2, 9)
fac[i] = fac[i - 1] * i;
fenjie[2].ps(2);fenjie[3].ps(3);
rep1(i, 4, 9)
{
dfs(2, i,0,1);
}
rei(n);
scanf("%s", s + 1);
rep1(i, 1, n)
temp[i] = s[i] - '0';
rep1(i,1,n)
if (temp[i] > 1)
{
int len = fenjie[temp[i]].size();
rep1(j, 0, len-1)
{
final_ans[++num] = fenjie[temp[i]][j];
}
}
sort(final_ans + 1, final_ans + 1 + num, cmp);
rep1(i, 1, num)
printf("%d", final_ans[i]);
puts("");
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 515C】Drazil and Factorial的更多相关文章

  1. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

  2. 【codeforces 515B】Drazil and His Happy Friends

    [题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...

  3. 【codeforces 515A】Drazil and Date

    [题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s ...

  4. codeforces 515C C. Drazil and Factorial(水题,贪心)

    题目链接: C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. 【codeforces 516B】Drazil and Tiles

    题目链接: http://codeforces.com/problemset/problem/516/B 题解: 首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解.然后如果这个图边双联 ...

  6. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  7. [codeforces 516]A. Drazil and Factorial

    [codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define  ...

  8. 【codeforces 546D】Soldier and Number Game

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

随机推荐

  1. uboot的GPIO驱动分析--基于全志的A10芯片【转】

    本文转载自:http://blog.csdn.net/lw2011cg/article/details/68954707 uboot的GPIO驱动分析--基于全志的A10芯片 转载至:http://b ...

  2. [python基础]xml_rpc远程调控supervisor节点进程

    supervisor提供的两种管理方式,supervisorctl和web其实都是通过xml_rpc来实现的. xml_rpc其实就是本地可以去调用远端的函数方法,在python中只需要引入xmlrp ...

  3. 自动生成Makefile的全过程详解

    一.简介 Linux下的程序开发人员,一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的 ...

  4. Nginx的alias与root的用法区别和location匹配规则

    1.alias与root的用法区别 最基本的区别:alias指定的目录是准确的,root是指定目录的上级目录,并且该上级目录要含有location指定名称的同名目录. location /abc/ { ...

  5. PCB genesis连孔加除毛刺孔(槽孔与槽孔)实现方法(三)

    一.为什么 连孔加除毛刺孔 原因是 PCB板材中含有玻璃纤维, 毛刺产生位置在于2个孔相交位置,由于此处钻刀受力不均导致纤维切削不断形成毛刺 ,为了解决这个问题:在钻完2个连孔后,在相交处再钻一个孔, ...

  6. Mechanize抓取数据【Ruby】

    创建: 2017/08/05 更新: 2018/01/08 修正: ele_inner_text -> ele.inner_text                           补充: ...

  7. E20170626-gg

    occupy   vt. 占领; 使用,住在…; 使从事,使忙碌; 任职; stack   n. 垛,干草堆; (一排) 烟囱; 层积; 整个的藏书架排列;

  8. Knights of the Round Table(Tarjan+奇圈)

    http://poj.org/problem?id=2942 题意:n个武士,某些武士之间相互仇视,如果在一起容易发生争斗事件.所以他们只有满足一定的条件才能参加圆桌会议:(1)相互仇视的两个武士不能 ...

  9. HTML-ul分分钟理解

    在HTML中,列表有三种,如图分别是有序.无序和自定义列表.上面是我在网络上找到的一张图片很明了就看以看出来,今天要分享的就是其中的无序列表Ul(unordered list),给大家整理了一下我所知 ...

  10. Python Base of Scientific Stack(Python基础之科学栈)

    Python Base of Scientific Stack(Python基础之科学栈) 1. Python的科学栈(Scientific Stack) NumPy NumPy提供度多维数组对象,以 ...