Timus 1209. 1, 10, 100, 1000... 根据数列推导公式
2014-04-24 10:35
483 查看
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.
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).
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.
这道题的关键就是要推导出公式了,如果使用循环,那么肯定是超时的。
根据数列的特征,知道循环的周期是1, 2, 3, 4, 5……
那么就可以知道需要计算k的位置是到了那个周期了,提示到这,看程序吧
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-thdigit of described above sequence.
Sample
input | output |
---|---|
4 3 14 7 6 | 0 0 1 0 |
根据数列的特征,知道循环的周期是1, 2, 3, 4, 5……
那么就可以知道需要计算k的位置是到了那个周期了,提示到这,看程序吧
void sequence1101001000() { int T = 0; long long k = 0, n = 0; cin>>T; while (T--) { cin>>k; if (k < 3) { cout<<1<<' '; continue; } n = sqrt((double)(k<<1)); n = ((1+n)*n)>>1; if (n+1 == k) cout<<1<<' '; else cout<<0<<' '; } }
相关文章推荐
- Timus 1209. 1, 10, 100, 1000...
- Timus - 1209 - 1, 10, 100, 1000...
- [timus] 1209. 1, 10, 100, 1000...
- (beginner problems) ural 1209 1, 10, 100, 1000...
- ural 1209. 1,10,100,1000.....
- ural 1209. 1, 10, 100, 1000... 二分
- 1.Timus 1209 求序列的第N位是0还是1: 1, 10, 100, 1000...组成序列1101001000...,求这个序列的第n位是0还是1
- URAL 1209. 1, 10, 100, 1000... (规律 + 二分)
- Ural 1209. 1, 10, 100, 1000... 一道有趣的题
- 根据日期及星期 ---- 蔡勒(Zeller)公式推导
- #读文笔记#马化腾:用户体验的10/100/1000法则
- 问题 : 1 10 100 1000
- 小技巧(四)分离字符串string str="(1,10,100,1000,10000,)";
- timus 1209. 1, 10, 100, 1000... URAL 解题报告
- 推导基姆拉尔森公式根据日期计算星期
- [51NOD1087]1 10 100 1000(规律,二分)
- 51nod--1087 1 10 100 1000
- 根据经纬度计算地面两点间的距离-数学公式及推导
- 小技巧(一)分离字符串string str="(1,10,100,1000,10000,)";
- [51nod] 1087 1 10 100 1000