【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 ...
随机推荐
- tflearn alexnet iter 10
他会自己下载数据: # -*- coding: utf-8 -*- """ AlexNet. Applying 'Alexnet' to Oxford's 17 Cate ...
- POJ3090 Visible Lattice Points 欧拉函数
欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...
- windows2003下svn的安装
Windows2003下svn平台搭建 编辑:dnawo 日期:2010-08-03 转自http://www.mzwu.com/article.asp?id=2557 字体大小: 小 中 大 ...
- FTP FtpWebRequest 异步上传文件
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- max_allowed_packet设置问题
最近在运行的项目出现了一个线上事故,有人反映商城的东西下不了单了,到后台看了一下,果然报了一个错 Cause: com.mysql.jdbc.PacketTooBigException: Packet ...
- Mac 的可清除空间(时间机器)
最近项目引入新技术flutter 所以需要更新xcode,下载完了xcode,安装不上 ,费解半天,提示磁盘空间不足.如下图,看到剩余九十多个G, 怎么都解决不了这个问题 就是买磁盘情理软件clean ...
- 7CSS之超链接
<!-- title="这是鼠标悬停时显示的文字" 鼠标悬停时,显示相关的文字--> <a href="#" title="这是鼠标 ...
- c/c++ 参数传递 - 数组
对于函数参数中的数组类型:传递的是数组地址,可以理解成传递的是对数组的引用.不是值传递,这是由C/C++函数实现机制决定的.一下三种函数生命完全等价: void func(int array[10]) ...
- Python--10、线程
线程 每个进程里都有一个控制线程,进程不是一个执行单位,线程是执行单位,进程是资源单位(资源隔离).进程下可以开多个线程,多线程共享进程内的资源.创建线程的速度比创建进程的速度快,因为创建线程不需要再 ...
- service里设置websocket心跳并向fragment发送数据
垃圾小白写了自己看的 /** * service 文件 */ public class SocketService extends Service { //自己定义接口用来传参 private sta ...