【codeforces 515C】Drazil and Factorial
【题目链接】: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的更多相关文章
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
- 【codeforces 515B】Drazil and His Happy Friends
[题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...
- 【codeforces 515A】Drazil and Date
[题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s ...
- codeforces 515C C. Drazil and Factorial(水题,贪心)
题目链接: C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 【codeforces 516B】Drazil and Tiles
题目链接: http://codeforces.com/problemset/problem/516/B 题解: 首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解.然后如果这个图边双联 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- [codeforces 516]A. Drazil and Factorial
[codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define ...
- 【codeforces 546D】Soldier and Number Game
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
随机推荐
- 在Java中实现UDP协议编程(DatagramSocket/DatagramPacket)
1.什么是UDP协议? UDP( User Datagram Protocol )协议是用户数据报,在网络中它与TCP协议一样用于处理数据包.在OSI模型中,在第四层——传输层,处于IP协议的上一层. ...
- 【Codeforces】Round #375 (Div. 2)
Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...
- bzoj3629 [JLOI2014]聪明的燕姿——DFS+约数和定理
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3629 扫除了一个知识盲点:约数和定理 约数和定理: 对于一个大于1正整数n可以分解质因数:n ...
- openStack aio 测试
- 58. Extjs grid CheckboxSelectionModel 单选
转自:https://kabuka.iteye.com/blog/581823 默认的 new Ext.grid.CheckboxSelectionModel 都是可以多选的,但是有时候需要控制单选时 ...
- Linux命令补充及基础优化。
1.用户部分 1.1 创建新用户 涉及命令 useradd [root@oldboyedu-50 ~]# useradd oldboy #添加用户 oldboy 1.2 设置密码 [root@oldb ...
- 使用js模拟ecshop元素挪移
<!DOCTYPE html><html><head> <title>移动</title> <script src="jqu ...
- robotframework - 运行报错提示 No keyword with name 'Open Browser' found.
用下面的例子为例: 1.输入以上robot脚本提示: 2.经查阅资料,大部分都使用的是selenium2 版本,无法解该的问题,目前小编使用的是selenium3,不知道selenium是哪个版本的话 ...
- drawable的文件名大写
drawable的文件名大写导致的R文件消失!!!1
- ACM_小G的循环
小G的循环 Time Limit: 2000/1000ms (Java/Others) Problem Description: 一回生,二回熟,三回就腻,小G用for,while循环用得太多了,累觉 ...