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 ...
随机推荐
- django搭建一个小型的服务器运维网站-查看服务器中的日志与前端的datatable的利用
目录 项目介绍和源码: 拿来即用的bootstrap模板: 服务器SSH服务配置与python中paramiko的使用: 用户登陆与session; 最简单的实践之修改服务器时间: 查看和修改服务器配 ...
- React Autocomplete(自动完成输入)示例教程
React Autocomplete示例教程是今天的主题.在现代Web开发中,使用React改善用户体验是很容易.自动完成的概念很简单.它是基于用户输入的建议列表.然后,用户可以按Enter键以完成短 ...
- 表格 td 设置宽度无效问题
现在有个需求,就是表格的列不固定,都是动态加载的,想给每一列设置宽度,但是设置 width:100xp,没有效果,不过设置min-width:100px 就有效果了,table的宽度为 td的宽度和 ...
- 170831-关于JdbcTemplate声明式事务-操作步骤-例子
创建一个动态web工程 加入jar包 3.创建一份jdbc.properties文件 4.在spring配置文件中配置数据源 5.测试数据源: 6.配置jdbcTemplate: 7.创建Dao类 & ...
- JS判断Android、iOS或浏览器的多种方法(四种方法)
第一种:通过判断浏览器的userAgent,用正则来判断是否是ios和Android客户端. 代码如下: <script type="text/javascript"> ...
- 【zabbix】zabbix 高可用架构的实现
https://www.jianshu.com/p/249d47b089b4?utm_campaign=maleskine&utm_content=note&utm_medium=se ...
- 高通平台Camera调试(一)【转】
本文转载自:http://www.voidcn.com/blog/Winva/article/p-6044730.html 4.3. Camera 参考文档: 1) 80-NA157-22_PRESE ...
- .net 4.5 Test Async Task 异步测试
using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Syst ...
- chales抓包,模拟异常情况
抓包能做什么? 1 .可以抓取客户端和server的请求和返回,可以借助判断是客户端问题是server问题 2.可以模拟各种异常情况用来测试异常情况 3.无接口文档情况下测试接口 怎么修改你抓到的请求 ...
- numpy多维数组
1 多维数组的切片用法 c = np.array([[[0,1,2],[4,5,6],[8,7,5],[10,11,12]],[[6,2,3],[9,8,34],[100,101,102],[110, ...