ACM PKU 1019 Number Sequence http://acm.pku.edu.cn/JudgeOnline/problem?id=1019
#include <iostream>
#include <cmath>
using namespace std;int Len(int n) // 求数字的长度函数;
{return log10(double(n)) + 1;
}int oj (int i, int temp) //一个比较傻的打表;不为别的,就选择最省时的;
{
if (temp < 10) return temp;
if (temp < 100)
{if (i == 1) return temp/10;else return temp%10;
}
if (temp < 1000)
{if (i == 3) return temp%10;if (i == 2) return (temp/10)%10;if (i == 1) return (temp/100);
}
if (temp < 10000)
{if (i == 4) return temp%10;if (i == 3) return (temp/10)%10;if (i == 2) return (temp/100)%10;if (i == 1) return (temp/1000);
}
if (temp < 100000)
{if (i == 5) return temp%10;if (i == 4) return (temp/10)%10;if (i == 3) return (temp/100)%10;if (i == 2) return (temp/1000)%10;if (i == 1) return (temp/10000);
}
if (temp < 1000000)
{if (i == 6) return temp%10;if (i == 5) return (temp/10)%10;if (i == 4) return (temp/100)%10;if (i == 3) return (temp/1000)%10;if (i == 2) return (temp/10000)%10; if (i == 1) return (temp/100000);
}
return 0;
}int research(int i)
{
__int64 sum = 0; //这个数非常大,引用的__int64;也是第一次用;
int temp = 1;
int j = 0;
int len = 0;
while (sum < i) //第一轮查找,找该数所在的串系列;
{// len = 0;// for (int m = 1; m <= temp; m++)本来是要去这样做的,结果发现len 可以保留,就直接拿来用了,效果不错;len+=Len(temp);sum+=len;temp++;
}
if (sum == i)
{temp = temp - 1;int turn = temp - (temp/10)*10;return turn;
}
else
{sum =sum - len;temp = 0;for (j = sum ; sum < i ; ) //第二轮查找,找到要找位的前一个数字;{temp++; sum +=Len(temp); }if (sum == i) return temp%10;else{sum -=Len(temp);i = i - sum;return oj(i,temp); //第三轮查找;确定最终位置的数字;}
}
}int main ()
{
int n ;
cin >> n;
while (n--)
{int num;cin >> num;cout<<research(num)<<endl;
}
return 0;
}
转载于:https://www.cnblogs.com/Chinese-Coder-Clarence/articles/2039265.html
ACM PKU 1019 Number Sequence http://acm.pku.edu.cn/JudgeOnline/problem?id=1019相关推荐
- ACM 1740 A New Stone Game http://acm.pku.cn/JudgeOnline/problem?id=1740
题目大意:有N堆石头,每堆石头数目在1到100之间,最多有10堆.两人分别取走石头.取石头的规则是:每次只能从1堆中取,每次取走至少1个.取过后还可以把这堆的石头任意分配到其它堆上(这些堆必须有石头, ...
- PKU ACM 1258 Agri-Net http://acm.pku.edu.cn/JudgeOnline/problem?id=1258
熟悉了prim算法后这样的题目在十分钟内真的可以解决!最小生成树,prim真的很有用! #include <iostream> using namespace std; const int ...
- Biorhythms ACM PKU http://acm.pku.cn/JudgeOnline/problem?id=1006
本题可以参考Wikipedia上线性同余同方程的解法,方法很简单手算一会就出来了.也可以参考中国同余定理:就这么多,下面我展示我的代码:#include <iostream> using ...
- pku acm 2140 Herd Sums http://acm.pku.edu.cn/JudgeOnline/problem?id=2140
2140代码短小精悍:#include<stdio.h> int main() { int cnt=0,i; long s; scanf("%ld",&s); ...
- ACM PKU 2663 Tri Tiling http://acm.pku.edu.cn/JudgeOnline/problem?id=2663
这题开始没有思路,后来看了流牛的解题报告才写出来: 递推公式我写一下: sign[i] = 1 (当i == 0 时,具体为什么我也没有具体的说明方法 ...
- ACM PKU 2559 Largest Rectangle in a Histogram http://acm.pku.edu.cn/JudgeOnline/problem?id=2559
关于覆盖,用DP是一种很不错的解决方法,时效也很不错.... 这题目把图一画就很明确了,没有说明的必要了. #include <iostream> using namespace std; ...
- ACM PKU 1111 Image Perimeters http://acm.pku.edu.cn/JudgeOnline/problem?id=1111
广搜永远记住,下标不要错,COPY时一定要记得改下标: #include <iostream> #include <queue> using namespace std;cha ...
- Hansel and Grethel ACM pku http://acm.pku.cn/JudgeOnline/problem?id=1254
1254是一道非常简单的关于平面直线相交问题的计算,只要注意一点: 斜率并不是所给出的指南针上的度数而应该是(90-degree):解决了此问题后所有的问题都迎刃而解了 我的代码如下: #includ ...
- PKU 3667 HDOJ 3667 Hotel ACM 3667 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 : http://poj.org/problem?id=3667 题目描述: Hotel Time Limi ...
最新文章
- VMWare中CentOS7 设置固定IP且能够访问外网
- 时间序列预测——线性回归(上下界、异常检测),异常检测时候历史数据的输入选择是关键,使用过去历史值增加模型健壮性...
- 【老孙随笔】属相影响你的职业前途吗?
- RK1109 RK1126等芯片来袭,2020年瑞芯微旗下SoC一览
- 【HDU - 5869】Different GCD Subarray Query(思维,数学,gcd,离线处理,查询区间不同数,树状数组 或 二分RMQ)
- Gmail的另类浏览法--RSS
- 【HDU5299】Circles Game,圆的扫描线+树上删边游戏
- PowerShell简介
- 智能机器人语音ic丨智能玩具语音识别芯片丨机器人语音播报芯片丨AI语音提示芯片...
- http/tcp/ip/端口
- react 复制antd表格行
- easyui的filebox过滤文件
- 1362:家庭问题(family)
- 【第16章】 网络安全风险评估技术原理与应用 (软考:信息安全工程师)-- 学习笔记
- Flask的大型网站模板
- Centos安装google浏览器01
- MATLAB boxplot 修改箱子线型、设置箱子颜色、不同长度数据画箱线图、中位线改成黑色、箱线图虚线改实线
- 【Unity3D—C#】按下任意按键,返回按键的名称 以及 KeyCode键码详解
- 河北单招计算机的考试试题,河北单招试题
- 你知道吗?炒鞋的那帮人,现在去炒数字藏品了
热门文章
- element的日期选择使用value-format之后表单验证报错
- oracle人才盘点演示,Oracle 11g Golden Gate DDL单向同步实例演示
- 【软考】面向对象程序设计复习指南
- larveral 直接拷贝安装_做一个能引导所有系统的安装盘
- Python源码深度解析—对象的创建
- [leetcode] 150. 逆波兰表达式求值
- OpenGL基础9:纹理
- bzoj 3609: [Heoi2014]人人尽说江南好(博弈)
- 图像读取、显示和保存
- python 一个简单的天气预报程序