Captain Flint and a Long Voyage

  • 题目
  • 解释
  • 代码

题目

Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it.

In the beginning, uncle Bogdan wrote on a board a positive integer x consisting of n digits. After that, he wiped out x and wrote integer k instead, which was the concatenation of binary representations of digits x consists of (without leading zeroes). For example, let x=729, then k=111101001 (since 7=111, 2=10, 9=1001).

After some time, uncle Bogdan understood that he doesn’t know what to do with k and asked Denis to help. Denis decided to wipe last n digits of k and named the new number as r.

As a result, Denis proposed to find such integer x of length n that r (as number) is maximum possible. If there are multiple valid x then Denis is interested in the minimum one.

All crew members, including captain Flint himself, easily solved the task. All, except cabin boy Kostya, who was too drunk to think straight. But what about you?

Note: in this task, we compare integers (x or k) as numbers (despite what representations they are written in), so 729<1999 or 111<1000.

Input
The first line contains a single integer t (1≤t≤1000) — the number of test cases.

Next t lines contain test cases — one per test case. The one and only line of each test case contains the single integer n (1≤n≤105) — the length of the integer x you need to find.

It’s guaranteed that the sum of n from all test cases doesn’t exceed 2⋅105.

Output
For each test case, print the minimum integer x of length n such that obtained by Denis number r is maximum possible.

Example
Input
2
1
3
Output
8
998
Note
In the second test case (with n=3), if uncle Bogdan had x=998 then k=100110011000. Denis (by wiping last n=3 digits) will obtain r=100110011.

It can be proved that the 100110011 is the maximum possible r Denis can obtain and 998 is the minimum x to obtain it.

解释

题意看半天居然挺懵逼的
题意大概是:
输入n
你需要输出十进制n位数x
这个十进制x满足:{
x的每一位转化成二进制,再加到一起的这个二进制数,
去掉最后n位,是最大的情况
}
而且,在0到9中,8(1000)和9(1001)这两个数字的二进制有四位,其他都少于四位,所以直接在8和9中选择结果

结合代码的注释差不多了

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{int t;cin >> t;while (t--){int n;cin>>n;//n代表2进制最后n位,也代表总数量 int q = n/4;//最后n位包含十进制的几位 if(n%4 != 0){//位数余出n%4位,就是十进制的那个数的二进制被切了一部分,只要有取余出,q++ q++;}for(int i=0 ; i<n-q ; i++){printf("9");}for(int i=0 ; i<q ; i++){printf("8");}printf("\n");}return 0;
}

参考:
Codeforces #660 (Div. 2) B. Captain Flint and a Long Voyage

Captain Flint and a Long Voyage相关推荐

  1. Codeforces Round #660 (Div. 2)

    A - Captain Flint and Crew Recruitment 刚开始还想筛法求质数,最后发现是个脑筋急转弯 #define IO ios::sync_with_stdio(false) ...

  2. Captain Icon – 350+ 有趣的矢量图标免费下载

    Captain Icon 是一套一个惊人的免费图标集,包含350+有趣的矢量图标,可以缩放到任意大小而不会降低质量.图标的类别很丰富,有设计,体育,社会,天气等很多类别.提供 EPS.PSD.PNG. ...

  3. Voyage 联合创始人目击苹果无人车,推测其计算堆栈集成在传感器中

    又有人在硅谷的马路上拍到了苹果正在测试的无人驾驶汽车,这一次不是什么路人甲,而是同在硅谷的自动驾驶初创公司 Voyage 的联合创始人 MacCallister Higgins .该公司已经在圣何塞( ...

  4. Mac升级到EI Captain之后pip install 无法使用问题

    错误log: creating /System/Library/Frameworks/Python.framework/Versions/2.7/share error: could not crea ...

  5. voyage java_GitHub - yezilong9/voyage: 采用Java实现的基于netty轻量的高性能分布式RPC服务框架...

    Voyage Overview 采用Java实现的基于netty轻量的高性能分布式RPC服务框架.实现了RPC的基本功能,开发者也可以自定义扩展,简单,易用,高效. Features 服务端支持注解配 ...

  6. 4152. [AMPPZ2014]The Captain(稠密图最短路)

    4152. [AMPPZ2014]The Captain 显然稠密图的边数时n2n^2n2量级,我们不可能把所有边建立出来,这时候通常寻求一些性质详细见[论题选编]稠密图最短路 针对本题我们可以先这样 ...

  7. OS X EI Captain 下解决 There was a problem confirming the ssl certificate 问题

    参考: Problem Confirming the SSL Certificate - OSX OS X EI Captain 下解决 There was a problem confirming ...

  8. OSX EI Captain中安装Pear等三方软件不成功的解决方法

    最近Mac更新到最新的OS X EI captain系统后, 在本地用PHP开发的时候发现苹果自带的PHP被重置了,所以之前的安装的PHP扩展都没了,本来Mac是自带pear包的,以为安装上PEAR包 ...

  9. el captain设置环境变量

    这里说的不是设置变量给bash/shell来用, 而是给程序使用, 比如, chromium自36版以后, 就不再内置google api keys, 官方文档(http://www.chromium ...

  10. Codeforces 474 C. Captain Marmot

    4*4*4*4暴力+点的旋转+推断正方型 C. Captain Marmot time limit per test 1 second memory limit per test 256 megaby ...

最新文章

  1. EF-InvalidOperation系列
  2. VC++ _T()宏学习
  3. .Net IOC框架入门之三 Autofac
  4. 太极团队内部邮件曝光:iOS8完美越狱重大突破
  5. Scala IDE for Eclipse的下载、安装和WordCount的初步使用(本地模式和集群模式)
  6. Array deduplication
  7. Codeforces | CF1029F 【Multicolored Markers】
  8. tableau货架图制作_3小时精通Tableau图表制作(18类)
  9. 库克宣布苹果将捐款帮助山西
  10. android iot代码设计,一个简单好用的Android Tab 设计与实现
  11. (实用工具分享)网页元素截图工具
  12. 使用Name Mangler快速为批量文件重命名
  13. PyCharm中的Debug使用
  14. JavaScript 3D 散点图
  15. linux服务器ftp连接失败的原因,错误:无法与 SFTP 服务器建立 FTP 连接
  16. 基于springBoot+MyBatis+Vue的前后端分离旅游管理系统
  17. MBI5020 16位恒流驱动芯片
  18. 如何将B站的flv格式的视频转换成mp4格式
  19. python超清壁纸_python爬虫 爬取超清壁纸代码实例
  20. 个人音乐流媒体服务器mStream

热门文章

  1. lzg_ad:XPE系统管理工具组件
  2. centos7安装steam
  3. python收取126或163邮件
  4. 《求职》第三部分 - 计算机网络篇 - 计算机网络总结
  5. 在腾讯待了 9 年还离了职
  6. TP5使用easywechat进行微信Native扫码支付
  7. (转)PQ分区魔术师中文版分区教程
  8. 南京计算机徐宪忠,nakaga
  9. svn 冲突 Error:Node remains in conflict
  10. JavaScript的document对象详解