1.题目描述:
类似于初中高中那种计算器的显示屏,给你n个笔画,问你能表示的最大数(不一定要把笔画数全部用完)
3.解题思路:
一开始想的是尽可能多的9,但是9是6画,完全可以变成71还剩下了一画,然后GG,再想——搜索??看了n很担心,但是还是交了一发,果然T了!!!
观察一下,10个数最少是1——2画,其次是7——3画,最多是8——7画,那么假设我们用9——5画,就有比它更优的解71(5画),用8也有比它更优的解711(7画),实际上我们可以证明最优的解就是在7(3画)和1(2画)之间选,而且7最多出现一次,因为一旦有大于两个7的话,比如771显然可以把两个7(笔画数为6)换为111三位数。
其实这个问题抽象一下,就是任何大于1的笔画数用由2和3尽可能多地表示,要你求出最大的个数,那么肯定是贪心地选取2,剩余再选3。
4.AC代码:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
int n, cnt;
while (~scanf("%d", &n))
{
if (n % 2 == 1)
{
printf("7");
cnt = (n - 3) / 2;
}
else
cnt = n / 2;
for (int i = 0; i < cnt; i++)
printf("1");
puts("");
}
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return 0;
}