三元排序
This commit is contained in:
parent
f457f39977
commit
e5b362ddbe
3
2015_sort_3num/Readme.md
Normal file
3
2015_sort_3num/Readme.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# 标题
|
||||||
|
|
||||||
|
* 内容
|
1
2015_sort_3num/doc/Readme.md
Normal file
1
2015_sort_3num/doc/Readme.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
#
|
BIN
2015_sort_3num/doc/三元排序.pdf
Normal file
BIN
2015_sort_3num/doc/三元排序.pdf
Normal file
Binary file not shown.
36
2015_sort_3num/main.cpp
Normal file
36
2015_sort_3num/main.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,a[100001],yi=0,er=0,ans=0;
|
||||||
|
cin>>n;
|
||||||
|
for(int i=1;i<=n;i++){
|
||||||
|
cin>>a[i];
|
||||||
|
if(a[i]==1){
|
||||||
|
yi++;
|
||||||
|
}
|
||||||
|
if(a[i]==2){
|
||||||
|
er++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int per=0;
|
||||||
|
for(int i=1;i<=yi;i++){
|
||||||
|
if(a[i]!=1){
|
||||||
|
ans++;
|
||||||
|
if(a[i]==2){
|
||||||
|
per++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=yi+1;i<=er+yi;i++){
|
||||||
|
if(a[i]!=2){
|
||||||
|
ans++;
|
||||||
|
if(a[i]==1&&per>0){
|
||||||
|
per--;
|
||||||
|
ans--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout<<ans;
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
2015_sort_3num/main.exe
Normal file
BIN
2015_sort_3num/main.exe
Normal file
Binary file not shown.
10
2015_sort_3num/test/in.txt
Normal file
10
2015_sort_3num/test/in.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
9
|
||||||
|
2
|
||||||
|
2
|
||||||
|
1
|
||||||
|
3
|
||||||
|
3
|
||||||
|
3
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
11
2015_sort_3num/test/in2.txt
Normal file
11
2015_sort_3num/test/in2.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
10
|
||||||
|
3
|
||||||
|
3
|
||||||
|
3
|
||||||
|
2
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
2
|
||||||
|
1
|
||||||
|
3
|
2
2015_sort_3num/test/in3.txt
Normal file
2
2015_sort_3num/test/in3.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1
|
||||||
|
1
|
18
2015_sort_3num/test/out.txt
Normal file
18
2015_sort_3num/test/out.txt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
## z:\Chao\src\2015_sort_3num\test\in.txt
|
||||||
|
2020/06/13 ÖÜÁù 10:23:28.60
|
||||||
|
4
|
||||||
|
-----------------------------------------------
|
||||||
|
Process exited after 150 ms with return value 0
|
||||||
|
|
||||||
|
## z:\Chao\src\2015_sort_3num\test\in2.txt
|
||||||
|
2020/06/13 ÖÜÁù 10:23:28.60
|
||||||
|
4
|
||||||
|
-----------------------------------------------
|
||||||
|
Process exited after 100 ms with return value 0
|
||||||
|
|
||||||
|
## z:\Chao\src\2015_sort_3num\test\in3.txt
|
||||||
|
2020/06/13 ÖÜÁù 10:23:28.60
|
||||||
|
0
|
||||||
|
-----------------------------------------------
|
||||||
|
Process exited after 100 ms with return value 0
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user