【codechef】Arush Challenge(灵活题)
来源:互联网 发布:网络摄像头ip搜索软件 编辑:程序博客网 时间:2024/05/24 15:36
Arush was not always poor at Mathematics but his recent performances had not been that good and he had lost his confidence. Now his elder brother was determined to bring back his confidence back in Mathematics.
So he made a tricky question and made sure that Arush would be able to do solve it. The factorial of a non-negative integer n, denoted by n! , is the product of all positive integers less than or equal to n.
n! = n * (n-1) * (n-2) * ...... * 1
Arush’s elder brother so defined a function F(x) for positive integer x as the product of factorials of its constituting digits.
For example, F(125) = 1! * 2! * 5!.
You are given a number N that contains d digits and contains at least one digit larger than 1.
The problem is to find maximum positive number M which should contain neither the digit 0 nor the digit 1 and also F(M) = F(N).
The number N may possibly start with leading zeroes.
Help Arush to bring his confidence back.
Input
- The first line of input contains T, the number of testcases.
- The first line contains an integer d, number of digits in N.
- Next line contains d digits of N.
Output
- Output the maximum possible integer M that satisfies the above conditions.
Constraints
Should contain all the constraints on the input data that you may have. Format it like:
- 1 ≤ T ≤ 50
- 1 ≤ d ≤ 15
Example
Input:2163006Output:5353
Explanation
Example case 1. d = 1, N = 6. Now F(6) = 6! = 720 and F(53) = 5! * 3! = 120 * 6 = 720.
http://www.codechef.com/problems/CLCO03
将当前数字转换,使得转换前后数字上每一位的阶乘的乘积相等。求转换后得到的最大的数字。
当前数的每一位(2-9)转换,在保证位数取到最大的情况下,数值取到最大。2,3,5,7都只能取到本身。
#include <bits/stdc++.h> using namespace std; int main(){ int t,n;<span style="font-family:Arial, sans-serif;color:#444444;"><span style="font-size: 12.307692527771px; line-height: 1.5em;"></span></span> string s; cin >> t; while ( t-- ) { cin >> n >> s; string ans = ""; for ( int i = 0; i < n; i++ ) { if ( s[i] == '0' || s[i] == '1' ) continue; else if ( s[i] == '4' ) ans += "223"; else if ( s[i] == '6' ) ans += "53"; else if ( s[i] == '8' ) ans += "2227"; else if ( s[i] == '9' ) ans += "7332"; else ans += s[i]; } sort(ans.begin(),ans.end()); //最后再从大到小排序,这样保证在位数最多的前提下,值也最大 reverse(ans.begin(),ans.end()); cout << ans << endl; } return 0;}
#include <bits/stdc++.h>using namespace std;int cnt[10];int main() {int t,d;long long n;scanf("%d",&t);while(t--){ scanf("%d",&d); scanf("%lld",&n); for(int i=0;i<10;++i) cnt[i]=0; while(n>0){ int dig=n%10; if(dig==2) cnt[2]++; else if(dig==3) cnt[3]++; else if(dig==4){ cnt[3]++; cnt[2]+=2; } else if(dig==5) cnt[5]++; else if(dig==6){ cnt[5]++; cnt[3]++; } else if(dig==7) cnt[7]++; else if(dig==8){ cnt[7]++; cnt[2]+=3; } else if(dig==9){ cnt[7]++; cnt[3]+=2; cnt[2]++; } n/=10; } for(int i=7;i>=2;--i){ for(int j=1;j<=cnt[i];++j) printf("%d",i); } printf("\n");}return 0;}
- 【codechef】Arush Challenge(灵活题)
- 【codechef】Gcd Queries(灵活题,分类)
- 【codechef】 Zeroes(大数灵活题)
- 【codechef】Strings Classes(枚举灵活题)
- 【codechef】Set Difference (灵活题,超时)
- 【codechef】The Warehouse(灵活题)
- 【codechef】Chef and Strange Formula(找规律,灵活题)
- 【codechef】Chef and Polygons(灵活题,坑题)
- 【codechef】括号匹配,求子串最大值(灵活题)
- codechef December Challenge 2012
- codechef December Challenge 2012
- codechef December Challenge 2012
- codechef May challenge A
- codechef May challenge B
- codechef May challenge C
- CodeChef May Challenge 2014
- codechef July Challenge 2014
- codechef December Challenge 2014
- atitit. it软件项目管理---自己的员工,雇佣军、援军,混合的员工 杂牌 人员管理架构
- Java线程面试题Top50
- git diff 的使用说明,是干什么的,怎么用!
- HDU 2069 Coin Change
- 黑马程序员——java线程学习笔记
- 【codechef】Arush Challenge(灵活题)
- 「HD_ACM」A+B for Input-Output Practice (VIII)
- 十道海量数据处理面试题与十个方法大总结
- CocoaPods安装和使用(SDWebImage)
- iOS 在应用内展示App Store 【StoreKit,SKStoreProductViewController】
- MongoDB操作
- 剑指offer 面试题38—数字在排序数组中出现的次数
- 如何降低代码的耦合
- ubuntu查找自己想要的函数库