| ||||||||||
| 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 | |||||||||
帮忙看看,我用的是那个啥数列的通项公式,我觉得是对的,就是不能AC
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
__int64 An[44];
__int64 Sn[44];
void initialize()
{
An[0]=0;
Sn[0]=0;
for(int n=1;n<44;n++)
{
An[n]=static_cast<__int64>(1/sqrt(5.0)*(pow((0.5+sqrt(5.0)/2),n)-pow((0.5-sqrt(5.0)/2),n)));
Sn[n]=Sn[n-1]+An[n];
}
}
void get_nm(__int64 a, int& n , __int64& m)
{
n=1;
for(n=1;a>Sn[n+2]-2;n++);
m=a-Sn[n+1]+2;
}
bool isItOne(int n ,__int64 m )
{
if(n>2)
{
if(m>An[n])
{
return isItOne(n-1,m-An[n]);
}
else
{
return isItOne(n-2,m);
}
}
else
{
if(n==1)
{
return m==1?1:0;
}
if(n==2)
{
return m==3?0:1;
}
}
}
__int64 xuhao(int n,__int64 m,int flag)
{
__int64 result=0;
if(flag==1)
{
if(n>2)
{
if(m>An[n])
{
result += An[n-1]+xuhao(n-1,m-An[n],1);
}
else
{
result += xuhao(n-2,m,1);
}
}
else
{
if(n==1)
{
return 1;
}
if(n==2)
{
return m==1?1:2;
}
}
}
if(flag==0)
{
if(n>2)
{
if(m>An[n])
{
result += An[n-2]+xuhao(n-1,m-An[n],0);
}
else
{
result += xuhao(n-2,m,0);
}
}
else
{
if(n==1)
{
return 1;
}
if(n==2)
{
return 1;
}
}
}
}
int main()
{
initialize();
for(;;)
{
__int64 a=0,b=0;
int na=0,nb=0;
__int64 ma=0,mb=0;
cin>>a>>b;
if(a>b)
{
__int64 c=a;
a=b;
b=c;
}
get_nm(a,na,ma);
get_nm(b,nb,mb);
int is_a_one=isItOne(na,ma);
int is_b_one=isItOne(nb,mb);
if(is_a_one==0)
cout<<1;
else
{
if(is_b_one==1)
cout<<1;
else
{
if(xuhao(na,ma,1)+Sn[na]-1==xuhao(nb,mb,0)+Sn[nb-1])
cout<<0;
else
cout<<1;
}
}
cout<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator