| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
why wrong answer????求救测试数据都快测完了 结果还是。。。。
大牛们能来帮下忙吗 谢谢
#include<stdio.h>
__int64 count[6], a[6][2];
__int64 search(__int64 n)
{
__int64 i=1,j=1,k;
__int64 sum=0,s,l=0,r,mid;
while(sum+count[i]<n) sum+=count[i++];
n-=sum;
r=a[i][1];
while(l<r)
{
mid=(l+r)/2;
sum=mid*a[i][0]+mid*(mid-1)/2*i;
if(sum>=n) r=mid;
else l=mid+1;
}
mid=r-1;
sum=mid*a[i][0]+mid*(mid-1)/2*i;
n-=sum;
while(n>a[j][1]*j)
{
n-=a[j][1]*j;
j++;
}
if(j==1) s=n/j;
else s=a[j][1]/9+(n-1)/j;
if(!(n%j)) return s%10;
for(k=0;k<j-n%j;k++)
s/=10;
return s%10;
}
int main()
{
int t,i;
__int64 n;
a[1][0]=1,a[1][1]=9;
for(i=1;i<=5;i++)
{
count[i]=a[i][1]*a[i][0]+a[i][1]*(a[i][1]-1)/2*i;
a[i+1][0]=a[i][0]+a[i][1]*i+1;
a[i+1][1]=a[i][1]*10;
}
scanf("%d",&t);
while(t--)
{
scanf("%I64d",&n);
printf("%I64d\n",search(n));
}
return 24;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator