ACM-HDOJ-1216 simulation, linked list

Source: Internet
Author: User

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]);
}
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.