input
2
3
4
output
7
11
我们来看一下下图,显然数字0需要六画、数字1需要两画,以此类推。
然后题目问,给你一个n,用n画能组成的最大整数是多少。
其实很简单,首先一个数要尽可能的大,首先需要考虑的是位数,其次是首位,因此我们要尽量选笔画少的数字,显然是1,只需要两画,那么当n为偶数时,n/2个1肯定是最大的数。然后我们再来考虑奇数,毋庸置疑的是,除了第一位外,后面肯定全是1,再观察一下所有数字的所需要的笔画,显然只需三画的较大整数7是最优的。
代码:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <map>
#include <math.h>
#include <set>
#include <vector>
#include <stack>
#include <sstream>
#define ll long long
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
if (n % 2 == 0)
{
n /= 2;
while (n--)
cout << "1";
cout << endl;
}
else
{
cout << "7";
n -= 3;
n /= 2;
while (n--)
cout << "1";
cout << endl;
}
}
return 0;
}