先上题目:

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

Time limit: 1.0 second
Memory limit: 64 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 integer N in the first line (1 ≤ N ≤ 65535). The i-th of N left lines contains the integer Ki — the number of position in the sequence (1 ≤ Ki ≤ 231 − 1).

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

input output
4
3
14
7
6
0 0 1 0

  题意:按照1,10,100,1000```的顺序将数字排在一起,从左往右,(10^i)<=(2^31-1),问第k位是0还是1。

  有人可以推出公式直接求第k位是0还是1,但是这里我用的方法不一样,首先我们可以得出第x个1出现的位置会是哪里:(x-1)*x/2+1=k,如果k符合这个条件就说明第k位是一个1否则就是0。不过如果枚举x来找k的话一定会超时,所以我们可以二分查找把x找出来,如果可以找出x说明是1,否则就是0了。

上代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
using namespace std; int check(LL k){
LL up=(1LL<<)-;
LL down=;
LL mid;
LL m;
while(up>=down){
mid=(up+down)/;
m=mid*(mid-)/+;
if(m==k) return ;
else if(m>k) up=mid-;
else down=mid+;
}
return ;
} int main()
{
int n,k;
//freopen("data.txt","r",stdin);
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&k);
if(i) printf(" ");
printf("%d",check(k));
}
printf("\n");
return ;
}

1209

Timus - 1209 - 1, 10, 100, 1000...的更多相关文章

  1. Ural 1209. 1, 10, 100, 1000... 一道有趣的题

    1209. 1, 10, 100, 1000... Time limit: 1.0 secondMemory limit: 64 MB Let's consider an infinite seque ...

  2. 1087 1 10 100 1000(打表 set 数学)

    1087 1 10 100 1000 题目来源: Ural 1209 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 1,10,100,1000... ...

  3. 51nod 1087 1 10 100 1000【打表】

    题目来源: Ural 1209 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 1,10,100,1000...组成序列1101001000...,求 ...

  4. 51Nod 1087 1 10 100 1000 | 数学

    Input示例 3 1 2 3 Output示例 1 1 0 #include "bits/stdc++.h" using namespace std; #define LL lo ...

  5. [51NOD1087]1 10 100 1000(规律,二分)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1087 用高中的数列知识就可以推出公式,不难发现f(n)=f(n ...

  6. 51NOD 1087 1 10 100 1000

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1087 暴力大法 #include<bits/stdc++.h> ...

  7. 背水一战 Windows 10 (100) - 应用间通信: 分享

    [源码下载] 背水一战 Windows 10 (100) - 应用间通信: 分享 作者:webabcd 介绍背水一战 Windows 10 之 应用间通信 分享 示例1.本例用于演示如何开发一个分享的 ...

  8. 用js实现随机选取10–100之间的10个数字,存入一个数组,并排序

    var iArray = []; function getRandom(istart, iend) { var iChoice = iend - istart + 1; //加1是为了取到100 va ...

  9. ResourceWarning: unclosed <socket.socket fd=864, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.100.x.x', 37321), raddr=('10.1.x.x', 8500)>解决办法

    将代码封装,并使用unittest调用时,返回如下警告: C:\python3.6\lib\collections\__init__.py:431: ResourceWarning: unclosed ...

随机推荐

  1. [BZOJ 1741] Asteroids

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1741 [算法] 将每颗小行星的行,列相连,问题就转化为了求这张图的最小覆盖 由kon ...

  2. C#(服务器)与Java(客户端)通过Socket传递对象(序列化 json)

    下面详细讲解实现的关键步骤:          通信关键: C#和java用Socket通信,发送数据和接收数据可以统一采用UTF-8编码,经过测试,使用UTF-8编码可以成功传递对象. 对于Sock ...

  3. (Go)07.strings与strconv的示例

    package main import ( "strconv" "fmt" "strings" ) func main() { str := ...

  4. [Apple开发者帐户帮助]三、创建证书(7)创建证书签名请求

    Mac上的Keychain Access允许您创建证书签名请求(CSR). 启动位于的Keychain Access /Applications/Utilities. 选择Keychain Acces ...

  5. APPStore 发布流程及证书申请

    最新的 iOS 申请证书与发布流程(2016.7) 今天刚好客户定制的APP需要上架,也提供了新的开发者账号,所以就顺带把申请证书与发布流程写一遍. 证书是什么? 上面这个就是我们申请好证书后,下载到 ...

  6. QQ 临时会话+图标 HTML代码

    啦啦啦 QQ会话的HTML代码 <a target="_blank" href="http://wpa.qq.com/msgrd?v=3& uin=2553 ...

  7. Apache 虚拟主机 配置方法

    打开httpd.conf文件 去掉LoadModule vhost_alias_module modules/mod_vhost_alias.so前面的#号 去掉Include conf/extra/ ...

  8. U - Three displays

    Problem description It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk ( ...

  9. Spring Boot (4) 静态页面和Thymeleaf模板

    静态页面 spring boot项目只有src目录,没有webapp目录,会将静态访问(html/图片等)映射到其自动配置的静态目录,如下 /static /public /resources /ME ...

  10. less 安装和webstorm的使用

    1.less 的安装 npm install -g less 2.less安装成功 3.less安装成功后,在webstorm中进行配置.file——>settings:弹出settings框, ...