ACM-杭电 HDOJ-1216 模拟,链表

    用下面的方法模拟,最开始开50000的链表跑了187ms,真是相当的惭愧呀。后改用35000的链表跑了109ms。最后改用c的输入输出(也就是下面放出的代码)跑了78ms,其实自己写链表会跑的更快。不过个人比较懒,加上已经0点了,78ms就78ms吧 = =~~~

 

    顺道一提,我这个代码加上空行什么的共737B,不过statistic第一页大多都是10000+B的代码,这神马情况 = =||

 

 
我的ac代码:
#include <iostream>
#include <cstdio>
#include <list>
#include <iterator>
#include <algorithm>

using namespace std;

int main() {
    list<int> l;
    list<int>::iterator pos = l.begin();
    int lucky[3001];
    int i(2);
    for ( ; i != 35000; ++i)
        l.push_back(i);

    for ( i = 0; i < 3001; ++i ) {
        lucky[i] = l.front();
        int key = lucky[i];
        pos = l.begin();
        while (pos != l.end()) {
            pos = l.erase(pos);
            int k = key - 1;
            while (k--) {
                if(pos == l.end())  break;
                ++pos;
            }
        }
    }

    int n;
    while (scanf("%d", &n), n){
        printf("%d\n", lucky[n - 1]);
    }

}

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值