poj Eeny Meeny Moo 我用链表暴力超时了!!!

 话说我就单纯的想练一下链表,没想明白每次暴力的时候都要申请空间,很浪费时间,以至于我超时,所以寡断打表了,下面是我暴力打表的代码!!!

#include<iostream>
using namespace std;
struct node
{
    int num;
    node *next;
};
node *head,*p,h;  
int main()
{
    int n;
    for(int n=3;n<=150;n++)
    {   
        int temp;    
        for(int i=2;i<10000;i++)
        {   
            h.next=NULL;
            head=&h;
            p=head;
            for(int po=1;po<=n;po++)
            {   
                p->next=(struct node*)malloc(sizeof(struct node));
                p=p->next;                
                p->num=po;
                if(po!=n)
                p->next=NULL;
                else
                p->next=head->next->next;
                
            }
            p=head;                   
            p->next=p->next->next;
            p=p->next;
            temp=i;
 //           cout<<i;
//            system("pause");
            while(p!=p->next)
            {   
                for(int j=1;j<=temp-2;j++)
                p=p->next; 
                
 //               cout<<p->next->num<<" "<<endl;
                p->next=p->next->next; 
                if(temp!=1)
                p=p->next;            
            }
            if(p->num==2)
            {
                printf(",%d",i);
                break;
            }
        }
    }
    system("pause");
    return 0;
}
                
            


 

#include<iostream>
using namespace std;
int a[180]={1,1,1,2,5,2,4,3,11,2,3,8,16,4,21,6,5,2,11,20,34,8,15,10,7,13,11,13,45,18,23,8,3,2,25,75,42,13,5,23,13,50,16,18,89,38,8,39,30,29,38,7,45,23,137,46,63,17,48,5,46,34,140,33,39,2,28,29,79,33,48,3,10,46,120,6,37,17,8,44,15,160,20,35,144,104,179,153,24,8,265,19,9,62,7,139,19,44,93,182,27,158,185,193,17,82,3,11,43,55,21,41,146,29,80,59,8,29,66,19,160,59,28,129,127,120,72,45,157,2,63,127,81,318,513,98,28,32,231,236,411,26,45,5,303,228,66,9,205,65,39};
int main()
{
    int n;
    while(cin>>n,n)
    cout<<a[n]<<endl;
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码随想录

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值