Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我觉得我写的肯定是这题最傻叉的代码。。。神牛门喷我吧。。。代码亮出

Posted by proverbs at 2012-07-30 00:08:25 on Problem 1019
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
__int64 a[32010],sum[32010],n,num,k,ans;
int main()
{
    n=32000;
    for(int i=1;i<=n;i++)
    {
        if(i<10) a[i]=a[i-1]+1;
        else if(i<100) a[i]=a[i-1]+2;
        else if(i<1000) a[i]=a[i-1]+3;
        else if(i<10000) a[i]=a[i-1]+4;
        else if(i<100000) a[i]=a[i-1]+5;
        else if(i<1000000) a[i]=a[i-1]+6;
    }
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    //for(int i=1;i<=10;i++) cout<<sum[i]<<endl;
    int tt;
    scanf("%d",&tt);
    while(tt--)
    {
        scanf("%I64d",&k);
        for(int i=1;;i++)
        {
            if(k<=sum[i]) {num=i-1;break;}
        }
        //cout<<num<<endl;
        __int64 tmp=sum[num];
        
        for(int i=1;;i++)
        {
            if(i<10) tmp+=1;
            else if(i<100) tmp+=2;
            else if(i<1000) tmp+=3;
            else if(i<10000) tmp+=4;
            else if(i<100000) tmp+=5;
            
            if(tmp>k)
            {
                num=i;
                break;
            }
        }
        //cout<<num<<endl;
        if(num<10)
        {
            ans=num-1;
        }
        else if(num<100)
        {
            tmp-=2;
            if(k-tmp==0) ans=(num-1)%10;
            else if(k-tmp==1) ans=num/10;
        }
        else if(num<1000)
        {
            tmp-=3;
            if(k-tmp==0) ans=(num-1)%10;
            else if(k-tmp==1) ans=num/100;
            else if(k-tmp==2) ans=(num/10)%10;
        }
        else if(num<10000)
        {
            tmp-=4;
            if(k-tmp==0) ans=(num-1)%10;
            else if(k-tmp==1) ans=num/1000;
            else if(k-tmp==2) ans=(num/100)%10;
            else if(k-tmp==3) ans=(num/10)%10;
        }
        else if(num<100000)
        {
            tmp-=5;
            if(k-tmp==0) ans=(num-1)%10;
            else if(k-tmp==1) ans=num/10000;
            else if(k-tmp==2) ans=(num/1000)%10;
            else if(k-tmp==3) ans=(num/100)%10;
            else if(k-tmp==4) ans=(num/10)%10;
        }
        cout<<ans<<endl;
    }
    system("pause");
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator