【题目链接】: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. WCF Odata 开放数据协议应用

    OData简介 说起 WCF Data Service ,不得不说的是 OData.对于一个标准的 Web 服务,它往往会提供了一些功能,比如说:订货.退货这些,然后使用者通过HTTP协议来使用这些功 ...

  2. bzoj 1453 双面棋盘

    题目大意: 一个黑白方格图 支持单点修改 查询黑色与白色联通快个数 思路: 可以把每一行压为一个点 使用线段树来维护 然后两行合并的时候使用并查集来合并 #include<iostream> ...

  3. createrepo -g /enp/comps.xml .

    cd /enp; createrepo -g /enp/comps.xml .

  4. 60.extjs-布局 (在column布局中使用fieldset 和 在fieldset中使用column布局)

    转自:https://blog.csdn.net/snn1410/article/details/8817821/ 在标准的html中,需要把输入项都放到fieldset中,一次来显示分组结构.虽然E ...

  5. 【TIDB】1、TiDb简介

    一 TiDb简介 TiDB 是 PingCAP 公司受 Google Spanner / F1 论文启发而设计的开源分布式 HTAP (Hybrid Transactional and Analyti ...

  6. jmeter中对于各类时间格式的设置

    最普通的设置为使用 函数助手中的__time, 设置好需要使用的类型,并设置接收参数即可 YMD = yyyyMMdd HMS = HHmmss YMDHMS = yyyyMMdd-HHmmss 第二 ...

  7. 337 House Robber III 打家劫舍 III

    小偷又发现一个新的可行窃的地点. 这个地区只有一个入口,称为“根”. 除了根部之外,每栋房子有且只有一个父房子. 一番侦察之后,聪明的小偷意识到“这个地方的所有房屋形成了一棵二叉树”. 如果两个直接相 ...

  8. Spring Cloud (5) 分布式配置中心

    Spring Cloud Config 在分布式系统中,由于服务数量很多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,使用Spring Cloud ...

  9. cocos2dx实现单机版三国杀(二)

    接上续,东西还没有做完 所以代码免不了改动 之前的头文件现在又改了不少,因为架构也改变了现在主要类就是GameScene.GameUI.PlayInfo.Poker这四个类  前面想的GameLoop ...

  10. [ SHOI 2012 ] 随机树

    \(\\\) \(Description\) 开始有一棵只有一个根节点的树.每次随机选择一个叶子节点,为他添上左右子节点,求: 生成一棵有\(N\)个叶节点的树,所有叶节点平均高度的期望. 生成一棵有 ...