银河

SKYIV STUDIO

  博客园 :: 首页 :: 博问 :: 闪存 :: :: :: 订阅 订阅 :: 管理 ::
  268 随笔 :: 2 文章 :: 2616 评论 :: 140万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
Timus 1209. 1, 10, 100, 1000... 要求给出特定序列的指定位置的值。

1209. 1, 10, 100, 1000...

Time Limit: 1.0 second
Memory Limit: 16 MB
Let's consider an infinite sequence of digits constructed of ascending powers of 10 written one after another. Here is the beginning of the sequence: 110100100010000… You are to find out what digit is located at the definite position of the sequence.

Input

There is the only positive integer number N in the first line, N < 65536. The i-th of N left lines contains the positive integer Ki — the number of position in the sequence. It's given that Ki < 231.

Output

You are to output N digits 0 or 1 separated with a space. More precisely, the i-th digit of output is to be equal to the Ki-th digit of described above sequence.

Sample

inputoutput
4
3
14
7
6
0 0 1 0
Problem Author: Alexey Lakhtin
Problem Source: USU Open Collegiate Programming Contest October'2002 Junior Session

这道题目是说,让我们考虑依次由10的非负整数次方连接在一起构成的无限序列:110100100010000…。你的任务是给出该序列指定位置的值。

通过仔细观察,可以看出,该序列中第 (x + 1) 个 1 位于第 N = 1 + (1 + 2 + ... x) = 1 + x(x + 1) / 2 个位置。解这个关于 x 的一元二次方程,得到它的非负根为:x = (√8N - 7 - 1) / 2。于是,当 x 是整数时,该序列中对应的第 N 个位置的值是 1,其余位置的值是 0。

下面就是相应的 C# 程序:

复制代码
 1 using System;
 2 
 3 // http://acm.timus.ru/problem.aspx?space=1&num=1209
 4 class T1209
 5 {
 6   static void Main()
 7   {
 8     for (int i = int.Parse(Console.ReadLine()); i > 0; i--)
 9     {
10       double x = (Math.Sqrt(8.0 * int.Parse(Console.ReadLine()) - 7- 1/ 2;
11       Console.Write(((x == (int)x) ? 1 : 0+ " ");
12     }
13   }
14 }
复制代码

返回目录
posted on   银河  阅读(1306)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示