Gym
来源:互联网 发布:南风知我意 七微 编辑:程序博客网 时间:2024/06/05 15:51
Using at most 7 matchsticks, you can draw any of the 10 digits as in the following picture:
The picture shows how many sticks you need to draw each of the digits.
Zaytoonah has a number that consists of N digits. She wants to move some sticks (zero or more) to maximize the number. Note that she doesn’t want to remove any of the sticks, she will only move them from one place to another within the N digits. She also doesn’t want to add new digits as N is her lucky number.
Can you help Zaytoonah maximize her number?
Input
The first line of input contains a single integer T, the number of test cases.
Each test case contains a single integer N (1 ≤ N ≤ 105), followed by a space, then N digits that represent the number Zaytoonah currently has.
Output
For each test case, print on a single line the maximum number Zaytoonah can get.
Example
Input
3
1 3
3 512
3 079
Output
5
977
997
思路:
在木棍数量确定的前提下,通过移动次数,来使得摆出的数量最大,我们能够得到十个数字每一个数字所示有的木棍的个数(它们在2-7之间),那么在确定一根的前提下,剩下的根数需要在 n-1 * 2 ~ n-1*7 之间,每一位都从大到小进行枚举,即可找到最大的情况
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[15]={6,2,5,5,4,5,6,3,7,6};char s[100100];int main (){ int t,n,m; scanf("%d",&t); while(t--) { scanf("%d %s",&n, s); m=strlen(s); int sum=0; for(int i=0; i<m;i++) { sum+=a[s[i]-'0']; } memset(s,0,sizeof(s)); for(int i=1;i<=n;i++) { for(int j=9;j>=0;j--) { if(sum-a[j]>=2*(n-i) && sum-a[j]<=7*(n-i)) { s[i-1]=j+'0'; sum-=a[j]; break; } } } puts(s); } return 0;}
阅读全文
0 0
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Android VideoView 播放视频
- js实现轮播图动画
- Codeforces Round #386 (Div. 2) A. Compote
- javascript:call与apply与bind
- 莫队总结
- Gym
- hdu6143Killer Names(组合递推+容斥原理)
- 泥塑课
- DrawerLayout
- Java 工具类
- 分享几个资源网站
- 多进程如何获取进程的返回值?用get函数,apply_async()
- eclipse设置代码自动提示
- G