The following method was used to simulate that the 50000 linked list was initially run for 187 ms, which is quite embarrassing. Later, we ran 35000 ms for the 109 linked list. Finally, I used the c input and output (that is, the Code released below) to run for 78 ms. In fact, writing a linked list by myself will run faster. However, I am relatively lazy, and I have already reached. For 78ms, 78ms = ~~~
By the way, I add a total of 737B blank lines to this code, but most of the first page of statistic is code of 10000 + B. This is a real situation: = |
Er, I learned from Baidu just now that the solution code for this question is quite good,
My ac code:
[Cpp]
# 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 = luky [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]);
}
}