Original title connection: http: //codeforces.com/gym/101102/problem/B
Meaning of the questions: put figures with a match stick, to ensure that the case of the same number of bits, the same number of matchsticks, the value as large as possible.
Ideas: first create an array that corresponds to the number of matchsticks each number needed. The outer loop to enumerate each and every inner loop digital election. Each digit with a minimum of two matchsticks, with up to seven, so the remaining few, use the median as the lower limit multiplied by 2, multiplied by 7 as the upper limit is determined only after the selection of the number of times the value of the remaining matches of this on whether to stick within a lower limit to complete the determination.
Complete code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; #define N 100005 char s[N]; int d[10]={6,2,5,5,4,5,6,3,7,6}; int main(){ int t,n; scanf("%d",&t); while(t--){ int sum=0; scanf("%d%s",&n,s); for(int i=0;i<n;i++){ sum+=d[s[i]-'0']; } for(int i=1;i<=n;i++){ int l=(n-i)*2,r=(n-i)*7; for(int j=9;j>=0;j--){ int a=sum-d[j]; if(a>=l&&a<=r){ sum-=d[j]; printf("%d",j); break; } } } printf("\n"); } return 0; }