杭电1250,求bug...
#include<stdio.h>#defineN10000000000inthead[4];__int64number[4][210];voidadd(intn){in...
#include<stdio.h>
#define N 10000000000
int head[4];
__int64 number[4][210];
void add(int n)
{
int i,m;
for(i = 0,m = 210;i < 4;i ++)
if(m > head[i])
m = head[i];
for(i = 209;i >= m;i --)
{
number[n%4][i] += number[(n+1)%4][i] + number[(n+2)%4][i] + number[(n+3)%4][i];
if(number[n%4][i] >= N)
{
head[n%4] = i - 1;
number[n%4][i - 1] += number[n%4][i] / N;
number[n%4][i] %= N;
}
else
head[n%4] = i;
}
}
int main(){
int n,i,j;
while(scanf("%d",&n) != EOF)
{
for(i = 0;i < 4;i ++)
for(j = head[i];j < 210;j ++)
number[i][j] = 0;
for(i = 0;i < 4;i ++)
{
head[i] = 209;
number[i][head[i]] = 1;
}
for(i = 5;i <= n;i ++)
add(i);
for(j = head[n%4];j <= 209;j ++)
{
if(number[n%4][j] == 0)
printf("0000000000");
else
printf("%I64d",number[n%4][j]);
}
printf("\n");
}
return 0;
} 展开
#define N 10000000000
int head[4];
__int64 number[4][210];
void add(int n)
{
int i,m;
for(i = 0,m = 210;i < 4;i ++)
if(m > head[i])
m = head[i];
for(i = 209;i >= m;i --)
{
number[n%4][i] += number[(n+1)%4][i] + number[(n+2)%4][i] + number[(n+3)%4][i];
if(number[n%4][i] >= N)
{
head[n%4] = i - 1;
number[n%4][i - 1] += number[n%4][i] / N;
number[n%4][i] %= N;
}
else
head[n%4] = i;
}
}
int main(){
int n,i,j;
while(scanf("%d",&n) != EOF)
{
for(i = 0;i < 4;i ++)
for(j = head[i];j < 210;j ++)
number[i][j] = 0;
for(i = 0;i < 4;i ++)
{
head[i] = 209;
number[i][head[i]] = 1;
}
for(i = 5;i <= n;i ++)
add(i);
for(j = head[n%4];j <= 209;j ++)
{
if(number[n%4][j] == 0)
printf("0000000000");
else
printf("%I64d",number[n%4][j]);
}
printf("\n");
}
return 0;
} 展开
2个回答
展开全部
#include<stdio.h>
#define N 10000000000LL
int head[4];
__int64 number[4][210];
void add(int n)
{
int i,m;
for(i = 0,m = 210;i < 4;i ++)
if(m > head[i])
m = head[i];
for(i = 209;i >= m;i --)
{
number[n%4][i] += number[(n+1)%4][i] + number[(n+2)%4][i] + number[(n+3)%4][i];
if(number[n%4][i] >= N)
{
head[n%4] = i - 1;
number[n%4][i - 1] += number[n%4][i] / N;
number[n%4][i] %= N;
}
else
head[n%4] = i;
}
}
int main(){
int n,i,j;
char buffer[100];
while(scanf("%d",&n) != EOF)
{
for(i = 0;i < 4;i ++)
for(j = 0;j < 210;j ++)
number[i][j] = 0;
for(i = 0;i < 4;i ++)
{
head[i] = 209;
number[i][head[i]] = 1;
}
for(i = 5;i <= n;i ++)
add(i);
for(j = head[n%4];j <= 209;j ++)
{
if(number[n%4][j] == 0)
printf("0000000000");
else
{
//printf("%I64d",number[n%4][j]);
sprintf(buffer,"%I64d",number[n%4][j]);
if(j==head[n%4])
printf("%s",buffer);
else
printf("%010s",buffer); // 需要补0
}
}
printf("\n");
}
return 0;
}
#define N 10000000000LL
int head[4];
__int64 number[4][210];
void add(int n)
{
int i,m;
for(i = 0,m = 210;i < 4;i ++)
if(m > head[i])
m = head[i];
for(i = 209;i >= m;i --)
{
number[n%4][i] += number[(n+1)%4][i] + number[(n+2)%4][i] + number[(n+3)%4][i];
if(number[n%4][i] >= N)
{
head[n%4] = i - 1;
number[n%4][i - 1] += number[n%4][i] / N;
number[n%4][i] %= N;
}
else
head[n%4] = i;
}
}
int main(){
int n,i,j;
char buffer[100];
while(scanf("%d",&n) != EOF)
{
for(i = 0;i < 4;i ++)
for(j = 0;j < 210;j ++)
number[i][j] = 0;
for(i = 0;i < 4;i ++)
{
head[i] = 209;
number[i][head[i]] = 1;
}
for(i = 5;i <= n;i ++)
add(i);
for(j = head[n%4];j <= 209;j ++)
{
if(number[n%4][j] == 0)
printf("0000000000");
else
{
//printf("%I64d",number[n%4][j]);
sprintf(buffer,"%I64d",number[n%4][j]);
if(j==head[n%4])
printf("%s",buffer);
else
printf("%010s",buffer); // 需要补0
}
}
printf("\n");
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询