Codeforces 515C 题解(贪心+数论)(思维题)
题面
传送门:http://codeforces.com/problemset/problem/515/C
Drazil is playing a math game with Varda.
Let’s define f(x)f(x)for positive integer x as a product of factorials of its digits. For example, f(135)=1!∗3!∗5!f(135)=1!∗3!∗5!
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:
x doesn’t contain neither digit 0 nor digit 1.
f(x)=f(a)f(x)=f(a)
Help friends find such number.
题目大意:
定义f(x)为x的每一位的阶乘之积
给出一个数a,求满足条件(x的每一位没有0或1)的最大x,使f(x)=f(a)
分析:
此题可用贪心求解
贪心的思路是很显然的,应该让x的位数尽量多,而每一位尽量小,最大的数应该排在最左边
这样,我们就可以把a的每一位拆开
如a=6
6!=6*5*4*3*2*1=6*5!=3!*5!
所以6可以被替换成35
所以我们把0~9的数字拆开(其实0,1应该直接舍去,因为不符合条件)
0!=0!
1!=1!
2!=2!
3!=3!
4!=3!*4=3!*2!*2!
5!=5!
6!=5!*6=5!*3!
7!=7!
8!=7!*8=7!*2!*2!*2!
9!=9*8*7!=7!*3!*3!*2!;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const string convert[10]={"0","0","2","3","322","5","53","7","7222","7332"};
string s;
string ans;
int n;
int cmp(char x,char y){
return x>y;
}
int main(){
scanf("%d",&n);
cin>>s;
ans="";
for(int i=0;i<n;i++){
if(s[i]-'0'==0||s[i]-'0'==1) continue;
ans=ans+convert[s[i]-'0'];
}
// cout<<ans<<endl;
sort(ans.begin(),ans.end(),cmp);
cout<<ans<<endl;
}
Codeforces 515C 题解(贪心+数论)(思维题)的更多相关文章
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
- Codeforces 1129E - Legendary Tree(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 考虑以 \(1\) 为根,记 \(siz_i\) 为 \(i\) 子树的大小,那么可以通过询问 \(S=\{2,3,\cdots,n\}, ...
- CodeForces - 427A (警察和罪犯 思维题)
Police Recruits Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- Codeforces 729D Sea Battle(简单思维题)
http://codeforces.com/contest/738/problem/D https://www.cnblogs.com/flipped/p/6086615.html 原 题意:海战 ...
- Codeforces 1365G - Secure Password(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 首先考虑一个询问 \(20\) 次的方案,考虑每一位,一遍询问求出下标的这一位上为 \(0\) 的位置上值的 bitwise or,再一遍 ...
- E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题
E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 848B Rooter's Song 思维题
http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标 ...
- Codeforces Round 56-A. Dice Rolling(思维题)
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
随机推荐
- Spring Boot 之Profile
Profile Profile是Spring对不同环境提供不同配置功能的支持,可以通过激活.指定参数等方式快速切换环境. 1)多Profile文件 我们在主配置文件编写的时候,文件名可以是:appli ...
- java IO操作分类
- vue制作分页
怎么制作分页?得先把思路路通顺了才可以. 我制作过程中遇到3个问题: 1,问:制作分页需要什么数据?怎么关联起来? 答:分页数据内容包含几部分, 1,当前是第几页?或则说当前默认是第几页. ...
- tomcat 启动一傘而过问题
tomcat 启动一傘而过问题 D:\apache-tomcat-7.0.75\bin startup.bat打开记事本打开 第一行:设置启动环境变量JAVA_HOME,CATALINA_HOME S ...
- SVN 没有弹出输入账号和密的界面
在用TortoiseSVN的时候,点SVN Checkout输入URL之后没有提示要输入账号密码的弹出框,直接跳到下一个界面,解决办法: 因为你在初次登陆svn的时候,点了保存密码的复选框,所以只要清 ...
- apache Internal Server Error 解决方法
https://blog.csdn.net/qq_33684377/article/details/78536548 https://blog.csdn.net/LJFPHP/article/deta ...
- 一本通例题埃及分数—题解&&深搜的剪枝技巧总结
一.简述: 众所周知,深搜(深度优先搜索)的时间复杂度在不加任何优化的情况下是非常慢的,一般都是指数级别的时间复杂度,在题目严格的时间限制下难以通过.所以大多数搜索算法都需要优化.形象地看,搜索的优化 ...
- python图像处理——频率域增强
图像的傅里叶变换: import chardet import numpy as np import cv2 as cv import cv2 from PIL import Image import ...
- Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 分类汇总统计mysql数据库一个字段中不同的记录的总和
方法1.用 if 语句,如下例. 方法2.用case when then else 语句,用法如同if. mysql> select sum(if(id<500,1,0)),sum(if( ...