| ||||||||||
| 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 | |||||||||
用基础的数学方法解此题,亲测算13用了91MS,为何说我超时?算法如下:
先使得a[1]=m%2k落在区间[k+1,2k]内,(a[1]=0的话赋值2k)
再递推a[i],使得a[i]=(m-(2k-i+1-a[i-1]))%(2k-i)落在[k+1,2k-i]内,(a[i]是0的话赋值2k-i)
i从1取到k都符合就输出m,否则m++
算13用了91MS,14用了330MS,虽然数字大了还是会超时,但是按照题目的数据和1000MS的时限应该没问题啊。求解。。。
#include <stdio.h>
int main()
{
int k,m=1,a,i;
scanf("%d",&k);
while(k!=0)
{
m=1;
i=0;
while(i<k)
{
a=m%(2*k);
if(a==0) {a=2*k;}
i=0;
while((a>=(k+1))&&(a<=2*k-i))
{
i++;
a=(m-(2*k-i+1-a))%(2*k-i);
if(a==0) {a=2*k-i;}
}
if(i<k) {m++;}
}
printf("%d\n",m);
scanf("%d",&k);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator