三元排序

This commit is contained in:
James 2020-06-13 10:32:59 +08:00
parent f457f39977
commit e5b362ddbe
9 changed files with 81 additions and 0 deletions

3
2015_sort_3num/Readme.md Normal file
View File

@ -0,0 +1,3 @@
# 标题
* 内容

View File

@ -0,0 +1 @@
#

Binary file not shown.

36
2015_sort_3num/main.cpp Normal file
View 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

Binary file not shown.

View File

@ -0,0 +1,10 @@
9
2
2
1
3
3
3
2
3
1

View File

@ -0,0 +1,11 @@
10
3
3
3
2
1
2
3
2
1
3

View File

@ -0,0 +1,2 @@
1
1

View 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