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 ...
随机推荐
- wpf socket 简单通讯示例
源码下载地址:https://github.com/lizhiqiang0204/WPF-Socket 效果如下:
- Selenium Java tutorial
https://eyes.applitools.com/app/test-results 1.
- bzoj3091 城市旅行 LCT + 区间合并
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3091 题解 调了整个晚自习才调出来的问题. 乍一看是个 LCT 板子题. 再看一眼还是个 LC ...
- CH0805 防线 (二分值域,前缀和,特殊性质)
$ CH~0805~ $ 防线 (二分值域,前缀和,特殊性质) $ solution: $ 注意博主所给题面的输出和原题有些不同 这道题当时想了很久很久,就是想不到怎么写.果然还是太 $ vegeta ...
- [洛谷3934]P3934 Nephren Ruq Insania题解
先放个奈芙莲 解法 看到这种题目就知道是欧拉降幂,然后根据某玄学证明,递归欧拉降幂从l到r不会超过\(\Theta(log_n)\),所以直接递归解决,然后区间修改直接树状数组维护一下 然后就A了 代 ...
- 在CentOS7中配置网络时常见的LSB加载失败问题
前几天,为了给OpenNebula扩展新的主机节点,对CentOS7的网络进行了配置.本以为网络配置只需要简单修改ifcfg-eth0即可,但是在重启网络服务时却遇到了一个LSB加载失败的问题(Fai ...
- uploadify加ASP.NET MVC3.0上传文件(可多条)
页面代码: <div id="fileQueuePlug"></div> <input type="file" name=&quo ...
- MySQL高可用方案 MHA之二 master_ip_failover
异步主从复制架构master:10.150.20.90 ed3jrdba90slave:10.15.20.97 ed3jrdba9710.150.20.132 ed3jrdba132manager:1 ...
- ASP 解析json
第一个方法是使用 JScript : <script language="jscript" runat="server"> Array.protot ...
- vundle的安装笔记-20160721
vundle是一个vim管理插件, 而bundle是命令, 用来操作vundle的. bundle 英[ˈbʌndəl] 美[ˈbʌndəl] n. 捆,束,包:大量:一大笔钱:极度 v. 归拢:捆: ...