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的 ...
随机推荐
- Linux文件类型及如何查看,修改文件读写权限
现在使用 ls -l 命令,查看详细信息格式的文件列表,您将会看到如下内容: total 5drwxr-x--- 4 user group 4096 Mar 10 00:37 filenamed ...
- 成为java高手的条件
世界上并没有成为高手的捷径,但一些基本原则是可以遵循的. 1.扎实的基础 数据结构.离散数学.编译原理,这些是所有计算机科学的基础,如果不掌握它们,很难写出高水平的程序.程序人人都会写,但当你发现写到 ...
- rails 常用的知识点
按惯例先上网址: http://guides.ruby-china.org/ 适合初学者很好的文章 ===========================知识点================ ...
- NPM
参考资料: 淘宝NPM
- git版本控制管理实践-3
git -m 和git -a -m(-am) . 的区别? usally two steps to commit files to respository: first, git add somefi ...
- Response.End()出现ThreadAbortException 异常
A. 如果使用 Response.End.Response.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常.异常内容:由于代码已经过 ...
- centos安装PHP服务器步骤
方法一.使用网友开发的EZHTTP程序包一键安装. 可以参考地址http://www.centos.bz/2013/08/ezhttp-tutorial/ http://www.cnblogs.com ...
- 利用session_set_save_handler()函数将session保存到MySQL数据库中
PHP保存session默认的是采用的文件的方式来保存的,这仅仅在文件的空间开销很小的windows上是可以采用的,但是如果我们采用uinx或者是liux上的文件系统的时候,这样的文件系统的文件空间开 ...
- 【Go入门教程3】流程(if、goto、for、switch)和函数(多个返回值、变参、传值与传指针、defer、函数作为值/类型、Panic和Recover、main函数和init函数、import)
这小节我们要介绍Go里面的流程控制以及函数操作. 流程控制 流程控制在编程语言中是最伟大的发明了,因为有了它,你可以通过很简单的流程描述来表达很复杂的逻辑.Go中流程控制分三大类:条件判断,循环控制和 ...
- php 跨域、跨子域,跨服务器读取session
1.跨子域和跨服务器解决方式 Session主要分两部分: 一个是Session数据,该数据默认情况下是存放在服务器的tmp文件下的,是以文件形式存在 另一个是标志着Session数据的Se ...