CF

来源:互联网 发布:linux tail命令 编辑:程序博客网 时间:2024/05/21 09:15

1.题目描述:

C. Maximum Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.

So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 66 sections must be highlighted.

The battery of the newest device allows to highlight at most n sections on the display.

Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer.

Input

The first line contains the integer n (2 ≤ n ≤ 100 000) — the maximum number of sections which can be highlighted on the display.

Output

Print the maximum integer which can be shown on the display of Stepan's newest device.

Examples
input
2
output
1
input
3
output
7

2.题意概述:

类似于初中高中那种计算器的显示屏,给你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_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);long _begin_time = clock();#endifint n, cnt;while (~scanf("%d", &n)){if (n % 2 == 1){printf("7");cnt = (n - 3) / 2;}elsecnt = n / 2;for (int i = 0; i < cnt; i++)printf("1");puts("");}#ifndef ONLINE_JUDGElong _end_time = clock();printf("time = %ld ms.", _end_time - _begin_time);#endifreturn 0;}

0 0
原创粉丝点击