CodeForces 515C. Drazil and Factorial
2 seconds
256 megabytes
standard input
standard output
Drazil is playing a math game with Varda.
Let's define
for positive integer x as a product of factorials of its digits. For example,
.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2.
=
.
Help friends find such number.
The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
4
1234
33222
3
555
555
In the first case, 
真的说,这道题目是比较简单的,只是我的想法有点问题。
我做的过程太过于复杂了!在中间操作过程已经使结果超过 long long
而JS相当于在中间过程有简单的优化,是我没想到的,我把每个数还原的过于简单了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <ctype.h>
using namespace std;
#define LL long long int main()
{
int n;
char num[];
int cnt[] = {};
int bit[];
while(scanf("%d%*c", &n) != EOF)
{
int tag = ;
for(int i = ; i < n; i++)
{
scanf("%c", &num[i]);
cnt[num[i] - '']++;
} for(int i = ; i < n; i++)
{
if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
}
sort(bit, bit+tag);
for(int i = tag-; i >= ; i--)
{
cout << bit[i];
}
cout << endl;
}
return ;
}
CodeForces 515C. Drazil and Factorial的更多相关文章
- codeforces 515C. Drazil and Factorial 解题报告
题目链接:http://codeforces.com/problemset/problem/515/C 题目意思:给出含有 n 个只有阿拉伯数字的字符串a(可能会有前导0),设定函数F(a) = 每个 ...
- CodeForces 515C Drazil and Factorial (水题)
题意:给出含有 n 个只有阿拉伯数字的字符串a,设定函数F(a) = 每个数字的阶乘乘积 .需要找出 x,使得F(x) = F(a),且组成 x 的数字中没有0和1.求最大的 x 为多少. 析:最大, ...
- CodeForces 516A Drazil and Factorial 动态规划
原文链接http://www.cnblogs.com/zhouzhendong/p/8990592.html 题目传送门 - CodeForces 516A 题意 对于一个正整数$x$,$f(x)=x ...
- codeforces 515C C. Drazil and Factorial(水题,贪心)
题目链接: C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C
C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- [codeforces 516]A. Drazil and Factorial
[codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define ...
- Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
A. Drazil and Factorial 题目连接: http://codeforces.com/contest/516/problem/A Description Drazil is play ...
- CF Drazil and Factorial (打表)
Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 【codeforces 515C】Drazil and Factorial
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...
随机推荐
- ubuntu14.04 下安装有道词典
安装步骤 1.ubuntu14.04.1版本下是不能直接安装有道词典的,首先需要把14.04.版升级为14.04.2版. 在终端窗口中输入以下命令: sudo apt-get update sudo ...
- log4Net控制台输出
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- Python之路【第十九篇】自定义分页实现(模块化)
自定义分页 1.目的&环境准备 目的把分页写成一个模块的方式然后在需要分页的地方直接调用模块就行了. 环境准备Django中生成一个APP并且注册,配置URL&Views 配置URL ...
- SqlServer 产生随机数
ALTER PROCEDURE [dbo].[usp_RandomNumber] ( , --随机数位数 --随机笔数 ) AS BEGIN DECLARE @T AS TABLE([Random N ...
- tail -f 和 -F 的用法
tail -f 和 -F 的用法 Tai 2010-08-16 16:03:18 -f 是--follow[=HOW]的缩写, 可以一直读文件末尾的字符并打印出来."[=HOW]" ...
- soj杂题
unique()函数是一个去重函数,STL中unique的函数 unique的功能是去除相邻的重复元素(只保留一个),还有一个容易忽视的特性是它并不真正把重复的元素删除.他是c++中的函数,所以头文件 ...
- php之jquery
<!DOCTYPE html> <html> <head> <script type="xxx.js"></script> ...
- 耿丹CS16-2班第一次作业汇总
第一次作业统计完成. 注:1.作业顺序:取最早交作业的前3名,依次拿5,2,1分,前提是作业质量较高,否则轮至下一名同学得分,其余同学得0分:2.作业情况:满10分,空一题扣2分,心得写得好的有额外加 ...
- 【转载】实时监听输入框值变化的完美方案:oninput & onpropertychange
oninput 是 HTML5 的标准事件,对于检测 textarea, input:text, input:password 和 input:search 这几个元素通过用户界面发生的内容变化非常有 ...
- source和./的区别
熟悉Linux的朋友常使用·bash·.·sh·.·source·.·.·,但却并非每位朋友都知道其中的区别.我们通过下面一幅图来为大家说明白.