Codeforces Round #660 (Div. 2) B. Captain Flint and a Long Voyage

题目链接

思路:

最后要删除后n位,那肯定是越长越好,二进制里面只有9和8是四位数,而9(1001)比8(1000)更符合删除后的,所有尽可能取9。

代码:

#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1e5+5;
const int M=2e4+5;
const double eps=1e-8;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926;
using namespace std;
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int cnt=n/4;
        if(n%4!=0)
        {
            cnt++;
        }
        for(int i=0;i<n-cnt;i++)
        {
            cout<<9;
        }
        for(int i=0;i<cnt;i++)
        {
            cout<<8;
        }
        cout<<endl;
    }
	return 0;
}

猜你喜欢

转载自blog.csdn.net/ACkingdom/article/details/107720564
今日推荐