先上题目:

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. ubuntu如何完全卸载和安装 Java及android环境?【转】

    本文转载自:https://my.oschina.net/lxrm/blog/110638 最近,迷上了java,一时间什么环境变量/虚拟机都猛然袭来,有点不适.环境配置在前,这所自然.平时搞PHP都 ...

  2. 源码中修改Android的开机画面和动画【转】

    本文转载自:http://blog.csdn.net/dddxxxx/article/details/54343976 参照文章:http://blog.csdn.net/a345017062/art ...

  3. 背包问题的方案总数 P1474 货币系统

    背包问题的方案总数 对于一个给定了背包容量.物品费用.物品间相互关系(分组.依赖等)的背包问题,除了再给定每个物品的价值后求可得到的最大价值外,还可以得到装满背包或将背包装至某一指定容量的方案总数. ...

  4. hdu 1035(DFS)

    Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  5. 【POJ 1964】 City Game

    [题目链接] http://poj.org/problem?id=1964 [算法] 记f[i]表示第i行最多向上延伸的行数 然后,对于每一行,我们用单调栈计算出这一行向上延伸的最大矩形面积,取最大值 ...

  6. 强连通分量--tarjan算法

    今天学了一个强连通分量,用tarjan做.北京之前讲过,今天讲完和之前一样,没有什么进步.上课没听讲,只好回来搞,这里安利一个博客:链接 https://blog.csdn.net/qq_343746 ...

  7. 0420-mysql命令(数据库操作层级,建表,对表的操作)

    注意事项: 符号必须为英文. 数据库操作层级: 建表大全: #新建表zuoye1:drop table if exists zuoye1;create table zuoye1(    id int ...

  8. CRMEB系统就是集客户关系管理+营销电商系统,能够真正帮助企业基于微信公众号、小程序实现会员管理、数据分析,精准营销的电子商务管理系统。可满足企业新零售、批发、分销、等各种业务需求。

    **可以快速二次开发的开源小程序商城系统源码**源码开源地址:https://github.crmeb.net/u/LXT 项目介绍: CRMEB系统就是集客户关系管理+营销电商系统,能够真正帮助企业 ...

  9. NOI2007项链工厂——sbTreap代码

    #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> ...

  10. angular js shopping

    <!DOCTYPE html>   <html lang="en">   <head>   <meta charset="UTF ...