看過問題討論,答案會循環,我把樓層%=20016 AC了
但是這滿不實際的,不知道樓層很大的時候大家怎麼算呢?
附上我的程式碼,我用link list 算
但是樓層太大的時候還是卡很久...不知道怎麼辦
#include <stdio.h>
#include <stdlib.h>
struct list
{
long long int x;
long long int posi;
struct list* next;
struct list* prev;
};
int main()
{
struct list *head =NULL;
struct list *cur =NULL;
struct list *prev =NULL;
//放第一筆資料
cur = (struct list *)malloc(sizeof(struct list));
cur->posi=0;
cur->x=1;
head=cur;
//放第二筆資料
cur->next = (struct list *)malloc(sizeof(struct list));
prev=cur;
cur=prev->next;
cur->prev=prev;
cur->posi=1;
cur->x=1;
cur->next=NULL;
long long int x;
while(scanf("%lld",&x)!=EOF)
{
cur=head;
while(cur->posi!=x)
{
if(cur->next!=NULL)
cur=cur->next;
else
{
cur->next = (struct list *)malloc(sizeof(struct list));
prev=cur;
cur=prev->next;
cur->next=NULL;
cur->prev=prev;
cur->posi=prev->posi+1;
cur->x=(cur->prev->x+cur->prev->prev->x)%10007;
}
}
printf("%lld\n",cur->x);
}
return 0;
}