12模拟链表,约瑟夫环。。来自一个失败的题意理解。。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
var a,b:array[0..10] of longint; n,i,t,k,j,p,m:longint; begin //readln(n); n:=10; for i:=1 to n do a[i]:=i; for i:=1 to n-1 do b[i]:=i+1; b[n]:=1; m:=0; t:=n; repeat for j:=1 to 3 do begin p:=t; t:=b[t]; end; b[p]:=b[t]; inc(m); until m=8; writeln(b[p]); t:=p; for k:=1 to 20 do begin write( a[t],' ' ); t:=b[t]; // end; end.
数组的STL快排:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <iostream> #include <algorithm> using namespace std; int main() { int i,a[10]; srand((int)time(0)); for(i=0;i<10;i++) { a[i]=rand()%30; cout<<a[i]<<" "; } cout<<endl; sort(a,a+10); for(i=0;i<10;i++) cout<<a[i]<<" "; cout<<endl; return 0; }
复赛新模板:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int i,j; //freopen("xxx.in", "r", stdin); //freopen("xxx.out", "w", stdout); //... //fclose(stdin); fclose(stdout); return 0; }
22