| ||||||||||
| 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 | |||||||||
Re:标准算法是用搜索吗?我用搜索,很快.....希望有确定的算法In Reply To:标准算法是用搜索吗?我用搜索,很快.....希望有确定的算法 Posted by:zcgzcgzcg at 2006-12-28 20:55:37 改为无法证明的确定算法,AC!
麻烦大家帮助证明:)
#include <stdio.h>
long a[31][2],yh[19+1],
success,n;
void print(long level)
{
long i,num=0;
printf("%ld",level);
for (i=1; i<=level; i++)
{
printf(" [%ld,%ld]",a[i][0],a[i][1]);
//num+=(1<<a[i][0])*(yh[a[i][1]]);
}
printf("\n");
}
void work(long level,long n,long mi2,long top3)
{
long i;
if (success)
return;
if (n==0)
{
print(level-1);
success=1;
return;
}
if (top3<0)
return;
while (!(n&1))
{
n/=2;
mi2++;
}
for (i=top3; i>=0; i--)
{
if (yh[i]>n)
continue;
if (!((n-yh[i])&1))
{
a[level][0]=mi2;
a[level][1]=i;
work(level+1,n-yh[i],mi2,i-1);
break; //important!!!
}
}
}
int main()
{
long i,t;
yh[0]=1;
for (i=1; i<=19; i++)
yh[i]=yh[i-1]*3;
scanf("%ld",&t);
for (i=1; i<=t; i++)
{
scanf("%ld",&n);
printf("%ld ",i);
success=0;
work(1,n,0,19);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator