用下面的方法模拟,最开始开50000的链表跑了187ms,真是相当的惭愧呀。后改用35000的链表跑了109ms。最后改用c的输入输出(也就是下面放出的代码)跑了78ms,其实自己写链表会跑的更快。不过个人比较懒,加上已经0点了,78ms就78ms吧 = =~~~
顺道一提,我这个代码加上空行什么的共737B,不过statistic第一页大多都是10000+B的代码,这神马情况 = =||
呃,刚才在百度知道,看到一个这个题的解题代码,感觉方法挺好的,放出一下链接:
http://zhidao.baidu.com/question/170953138.html&__bd_tkn__=42a51a3b382190374e53e579e5fd36fbcf0abba68078338d51fed8133ea5c69d362ad36bb4bcda3b39bb3949f6bbe47087ac3af56e60b1f4e7eb6015795bfd3b9864a8fb560f03de0125277da631b87a330693740c5fcff9d744337c765b3b2fc5640b364eb4a4dfec7ef9accbdc8d03cf3424f24ba0
我的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]);
}
}