Educational Codeforces Round 81 (Rated for Div. 2)A. Display The Number

A. Display The Number

题目链接-Display The Number
在这里插入图片描述
在这里插入图片描述
题目大意
电子显示屏上一个数字的每个位置由7个段组成,可以打开和关闭以组成不同的数字。不能同时打开超过n个段。现在您想知道通过启用不超过n个分段可以显示的最大整数是多少。

解题思路
贪心思想
由题意易得输出的最大整数会爆long long

数字 0 1 2 3 4 5 6 7 8 9
段数 6 2 5 5 4 5 6 3 7 6

优先用2个小段来凑1.
如果为奇数的话,多出来一段,就用3小段来凑个7放在开头
(如果先用6小段凑9的话不如先用6小段凑111)
附上代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF=0x3f3f3f;
int a[10];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n%2==0)
			for(int i=0;i<n/2;i++)
				cout<<"1";
		else{
			cout<<"7";
			n-=3;
			for(int i=0;i<n/2;i++)
				cout<<"1";
		}
		cout<<endl;
	}
	return 0;
}
发布了14 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Fiveneves/article/details/104114509