Question:http://poj.org/problem?id=1019
问题点:打表。
 Memory: 392K        Time: 16MS
Language: C++ Result: Accepted #include <iostream>
#include <cmath>
using namespace std; #define uint unsigned int
uint table[];
uint a[] = {,,,,,};//(1-10^k)/(1-10)的对应结果
uint b[] = {,,,,,};//[1...j]中位数变动边界值。如9 10,从个位到十位时记录9的偏移量
int getLen(int n)
{
if(n<) return ;
else if(n<) return ;
else if(n<) return ;
else if(n<) return ;
else return ;
}
int main()
{
uint i=,seg;
memset(table,,sizeof(table));
for(i = ,seg = ;i<;i++)//打表
{
seg += getLen(i);
table[i] = table[i-] + seg;
}
uint eg,num,j,k,bit;
cin>>eg;
while(eg--)
{
cin>>num;
//if(num==0) break;
for(j=;j<i&&num>table[j];j++);//对应段[1...j]的最大数j
num -= table[j-];//num在[1...j]中的偏移量
for(k=;num>b[k];k++);//num所在数字有几位:如 num偏移为12,所在数字为11,长度k=2
//下面的两个公式简单说明一下:
//如 j=101:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... 100 101
//当所在数字(同上面注释里的所在数字)n=19时,偏移量 offset = 19 + (19-9) ,即个位数字数 + 十位数字数
//所以,当n的长度为k时,offset = n + (n-9) +(n-99) +...+(n-(k-1个9)) =k(n+1) -(1+10+100+...+10^(k-1))=k(n+1)-(1-10^k)/(1-10)
//(1-10^k)/(1-10)已存到数组a中,则offset = k(n+1) - a[k],下面两个公式都是依此推导
bit = (num + a[k] - k - )%k;//计算num在 所在数字的位置 :如num为13指向所在数字12的十位,则bit=0(bit从数字高位到低位递增)
num = (ceil(double(num + a[k])/k-));//计算num的所在数字的值
char buf[];
sprintf_s(buf,"%d",num);
cout<<buf[bit]<<endl;//数字转字符串,输出指定位置字符
}
//system("pause");
return ;
}

北大ACM(POJ1019-Number Sequence)的更多相关文章

  1. POJ1019——Number Sequence(大数处理)

    Number Sequence DescriptionA single positive integer i is given. Write a program to find the digit l ...

  2. POJ1019 Number Sequence

    Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36256   Accepted: 10461 ...

  3. ACM—Number Sequence(HDOJ1005)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 主要内容: A number sequence is defined as follows: f ...

  4. 杭电ACM刷题(2):1005,Number Sequence 标签: 杭电acmC语言 2017-05-11 22:43 116人阅读

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  5. ACM学习历程——HDU 5014 Number Sequence (贪心)(2014西安网赛)

    Description There is a special number sequence which has n+1 integers. For each number in sequence, ...

  6. 北大 ACM 分类 汇总

    1.搜索 //回溯 2.DP(动态规划) 3.贪心 北大ACM题分类2009-01-27 1 4.图论 //Dijkstra.最小生成树.网络流 5.数论 //解模线性方程 6.计算几何 //凸壳.同 ...

  7. [2011山东ACM省赛] Sequence (动态规划)

    Sequence Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Given an integer number sequence ...

  8. 1005 Number Sequence(HDU)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 Number Sequence Time Limit: 2000/1000 MS (Java/O ...

  9. HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  10. HDU 1711 Number Sequence(KMP裸题,板子题,有坑点)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. win7如何更改语言教程

    一.首先从桌面左下角的开始菜单中找到“控制面板”,然后打开,如下图所示: 打开电脑控制面板 二.进入控制面板之后,我们再进入“时钟.语言和区域”设置,如下图所示: 电脑语言改成英文方法 三.进入电脑语 ...

  2. [Spring] Properties for project configuration

    We might have some project specific configuration need to setup. The good approach to do this in Spr ...

  3. ldd LD_TRACE_LOADED_OBJECTS

    1 该环境变量设置为1的话,只会打印所执行的程序的依赖,即所依赖的动态链接库

  4. win32gui.EnumWindows my.os.EnumWindows.py

    import win32guidef _MyCallback(hwnd, extra): windows = extra temp = [] temp.append(hex(hwnd)) temp.a ...

  5. Java的Graphics中drawImage与drawLine的坐标区别

    drawImage复制的区域是 dx1 <= x < dx2,dy1 <= y < dy2 drawLine绘制区域是 dx1 <= x <= dx2,dy1 &l ...

  6. Cordova 开发 App

    Cordova 是一个开源的移动开发框架.允许你用标准的 Web 技术——HTML5,CSS3 和 JavaScript 做跨平台开发.应用在每个平台的具体执行被封装了起来,并依靠符合标准的 API ...

  7. hdoj--2187--悼念512汶川大地震遇难同胞——老人是真饿了(贪心)

     悼念512汶川大地震遇难同胞--老人是真饿了 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  8. softmax function in c++

    #include <iostream> #include <vector> #include <cmath> #include <algorithm> ...

  9. win7 32位解决matlab out of memory问题

    由于最近在做DL,matlab load数据时由于内存只有2G,会出现out of memory的情况,网上百度了下都是在xp下打开3GB来解决该问题,但是由于win7没有boot.ini无法在win ...

  10. bzoj4873

    http://www.lydsy.com/JudgeOnline/problem.php?id=4873 最大权闭合子图... 建图: 1.d[i][j]:i->j区间的费用,d[i][j] & ...