poj-2514-模拟
http://poj.org/problem?id=2514
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1954 | Accepted: 412 |
Description

The first digit of the result is 2, the second digit is 7, and the third is 2 and so on. Given an integer k, you should output the digit at position k in the resulting number.
Input
A line containing a number "0" terminates input, and this line need not be processed.
Output
Sample Input
2
5
30
0
Sample Output
7
1
8
Source
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
#define LL long long
vector<LL>g[];
LL a[],b[];
LL max_int=;
void init()
{
g[].push_back();
g[].push_back();
LL x=,y=;
for(int i=; i<=; ++i,x=x*+,y*=)
{
g[].push_back(x);
g[].push_back((LL)(sqrt(y)-0.00001));
}
LL o=;
for(int i=; i<=; ++i,o*=)
{
a[i]=a[i-]+i*(o-o/);
}
for(LL i=; i<=; ++i)
{
b[i]=b[i-]+i*(g[][i]-g[][i-]);
}
}
int getl(LL n)
{
int ans=;
while(n) ans++,n/=;
return ans;
}
int get_a(LL n)
{
LL l=,r=;
while(l<r)
{
LL mid=l+(r-l)/;
LL len=getl(mid);
LL s=a[len-]+(len*(mid-g[][len-]));
if(s>n)
{
r=mid;
}
else if(s<n)
{
l=mid+;
}
else
{
return mid%;
}
}
LL len=getl(l);
LL s=a[len-]+(len*(l-g[][len-]));
while(s>n) s--,l/=;
return l%;
} int get_b(LL n)
{
LL l=,r=;
while(l<r)
{
LL mid=l+(r-l)/;
LL len=getl(mid*mid);
LL s=b[len-]+(len*(mid-g[][len-]));
if(s>n)
{
r=mid;
}
else if(s<n)
{
l=mid+;
}
else
{
return mid*mid%;
}
}
LL len=getl(l*l);
LL s=b[len-]+(len*(l-g[][len-]));
l=l*l;
while(s>n) s--,l/=;
return l%;
} int main()
{
LL n;
init();
while(scanf("%lld",&n)!=EOF)
{
if(!n) break;
LL a=get_a(n),b=get_b(n),
c=get_a(n+),d=get_b(n+),jin=;
while(c+d>)
{
if(c+d>)
{
jin=;
break;
}
n++;
c=get_a(n+);
d=get_b(n+);
}
cout<<(a+b+jin)%<<endl;
}
return ;
}
poj-2514-模拟的更多相关文章
- POJ 1016 模拟字符串
Numbers That Count Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20396 Accepted: 68 ...
- POJ 1208 模拟
2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...
- POJ - 3087 模拟 [kuangbin带你飞]专题一
模拟洗牌的过程,合并两堆拍的方式:使先取s2,再取s1:分离成两堆的方式:下面C张放到s1,上面C张到s2.当前牌型与第一次相同时,说明不能搜索到答案. AC代码 #include<cstdio ...
- Shuffle'm Up POJ - 3087(模拟)
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15249 Accepted: 6962 Des ...
- poj 1379 模拟退火法
/* 模拟退火法: 找到一些随机点,从这些点出发,随机的方向坐标向外搜索: 最后找到这些随机点的最大值: 坑://if(xx>-eps&&xx<x+eps&& ...
- POJ 1471 模拟?
题意:求最大无坏点三角形 思路: 模拟? (为什么我模拟过了...) 有人用 DP,有人用 搜索... // by SiriusRen #include <cstdio> #include ...
- POJ 1951 模拟
思路: 坑爹模拟毁我一生 给两组数据: 输入: YOURE TRAVELING THROUGH ANOTHER DIMENSION A DIMENSION NOT OF SIGHT. 输出: YR T ...
- POJ 2141 模拟
思路:字符串解密 啥都告诉你了 模拟就好 //By SiriusRen #include <cstdio> #include <cstring> using namespace ...
- POJ 2459 模拟
题意: 思路: 按照题意模拟即可 //By SiriusRen #include <cstdio> using namespace std; int c,f1,f2,d,xx,yy,vis ...
- poj 1068 模拟
题目链接 大概题意就是告诉你有个n个小括号,每一个")"左边有多少个"("都告诉你了,然后让你求出每一对括号之间有多少对括号(包含自己本身). 思路: 我先计算 ...
随机推荐
- Linux 下终端 C 语言控制光标的技巧
// 清除屏幕 #define CLEAR() printf("\033[2J") // 上移光标 #define MOVEUP(x) printf("\033[%dA& ...
- linux mysql操作命令大全
1.linux下启动mysql的命令:mysqladmin start/ect/init.d/mysql start (前面为mysql的安装路径) 2.linux下重启mysql的命令:mysqla ...
- Intellij idea 添加浏览器
最近的项目要做一个海康的网页端的监控,需要下载海康的插件,但是试验了一下,Chrome和IE的都不支持插件的显示,只有搜狗的显示,但是Idea的默认浏览器里面没有,所以要添加一个默认的浏览器 方法很简 ...
- JDBC连接数据库的安全性连接方法
PreparedStatement ps=null; ResultSet rs=null; Connection ct=null; try { Class.forName("com.mysq ...
- [osg]osg绘制动态改变顶点的几何体
最简单的顶点数据更新方法是预先获取setVertexArray()所用的数组数据,并对其进行更新.但是对于开启显示列表支持的几何体(这是默认的情况)来说,有一个问题需要特别需要引起注意,即显示列表中的 ...
- Ubuntu16 源码方式安装postgresql数据库
依赖工具库 注意:默认用户名是postgres,以下命令是Ubuntu操作系统中的命令 make GCC Zlib 安装命令:sudo apt-get install zlib1g-dev注意有些软件 ...
- Eclipse+maven 构建第一个简单的springmvc项目
先给出项目的目录: 在eclipse下使用maven构建第一个springmvc项目步骤如下: 1.创建maven project(此处默认你已了解maven),此处需要注意以下两点 2.创建完毕后会 ...
- arcpy导入错误 问题 “ImportError: No module named arcpy”
如果阁下也出现如下图的错误,用本文的方法也许可以解决问题 首先,打开你python的安装位置,如下图所示的路径,找到desktop10.3.pth文件,打开查看,将你arcgis的相关路径,共3个绝对 ...
- 第 3 章 镜像 - 021 - Docker 镜像小结
镜像小结 镜像的常用操作子命令: images 显示镜像列表 history 显示镜像构建历史 commit 从容器创建新镜像 build 从 Dockerfile 构建镜像 ...
- 日常英语---十二、MapleStory/Monsters/Level 1-10(Horny Mushroom)
日常英语---十二.MapleStory/Monsters/Level 1-10(Horny Mushroom) 一.总结 一句话总结: horny-['hɔːnɪ]-adj.角的 Another m ...