51nod 1435 位数阶乘 (思维水题)
来源:互联网 发布:使命召唤ol流畅优化 编辑:程序博客网 时间:2024/06/06 20:11
1435 位数阶乘
题目来源: CodeForces
基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
收藏
关注
X是一个n位数的正整数
现在定义
我们给定一个n位数的整数X(至少有一位数大于1,X中可能有前导0),
然后我们去找一个正整数(s)符合以下条件:
1.这个数尽可能大,
2.这个数中不能含有数字0或1。
3.F(s)=F(x)
Input
每个测试数据输入共2行。第一行给出一个n,表示x为中数字的个数。(1<=n<=15)第二行给出n位数的正整数X(X中至少有一位数大于1)
Output
共一行,表示符合上述条件的最大值。
Input示例
41234
Output示例
33222
System Message (题目提供者)
思路:不知道为什么这题竟然是4级题, 一会就会了。。 能变成2,3的阶乘就变成2,3的阶乘, 而且2一定比3多, 5,7的阶乘都不能拆, 只能是自己....
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;char s[20];int cnt[20];int main(){ int n; cin >> n; cin >> s; int len = strlen(s); for(int i = 0; i < len; i++) { if(s[i] == '0' || s[i] == '1') cnt[1]++; if(s[i] == '2') cnt[2]++; if(s[i] == '3') cnt[2]++, cnt[3]++; if(s[i] == '4') cnt[2]+=3, cnt[3]++; if(s[i] == '5') cnt[5]++; if(s[i] == '6') cnt[2]++, cnt[3]++, cnt[5]++; if(s[i] == '7') cnt[7]++; if(s[i] == '8') cnt[2]+=3, cnt[7]++; if(s[i] == '9') cnt[3]+=2, cnt[2]+=3, cnt[7]++; } cnt[2] -= cnt[3]; for(int i = 7; i >= 2; i--) { if(cnt[i]) { for(int j = 1; j <= cnt[i]; j++) printf("%d", i); } } return 0;}
阅读全文
2 0
- 51nod 1435 位数阶乘 (思维水题)
- 51nod 1435 位数阶乘 (简单题)
- 51nod 1435:位数阶乘
- 51nod-1435 位数阶乘
- 51nod 1435 位数阶乘
- 51nod 1435 位数阶乘
- 51 nod 1435 位数阶乘
- 51nod 1435 位数阶乘 (手动计算)
- 51nod 1435 位数阶乘 找规律
- 51Nod-1435-位数阶乘
- 51nod 1058 阶乘的位数
- 51nod 1435 数位阶乘 思路题
- 51Nod-1003 阶乘后面0的数量【分析思维】
- 51Nod 1272(思维题)
- 1435 位数阶乘
- 1435 位数阶乘
- 51NOD1435 位数阶乘
- 51Nod - 1276 思维题
- bootstrap实现垂直导航框架
- 设计模式基础
- 如何在Linux上安装Mysql的二进制包(mysql-xxx-linux-xxx-x86_64.tar)
- 个人读书笔记---“深入理解java虚拟机”---垃圾回收
- Codeforces Round #428 (Div. 2) A B C
- 51nod 1435 位数阶乘 (思维水题)
- Java接口中的成员变量为什么必须是public static final?
- HTML菜鸟入门1
- 字符串转换为整型
- Linux_shell条件判断if中的-a到-z的意思
- bzoj 2212 [Poi2011]Tree Rotations(线段树合并)
- 入门树状数组(左边比x小的个数)
- python学习(十)----matplotlib模块相关函数
- 17/8/18