麻烦的聚餐

This commit is contained in:
James 2020-05-03 11:15:55 +08:00
parent 411ab83b38
commit 0a9a03ccec
9 changed files with 106 additions and 0 deletions

3
2862_cow/Readme.md Normal file
View File

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

1
2862_cow/doc/Readme.md Normal file
View File

@ -0,0 +1 @@
#

Binary file not shown.

61
2862_cow/main.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <iostream>
using namespace std;
int mins(int yi,int er){
return yi<er? yi:er;
}
int main()
{
int n,a[30001]={0};
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int f[30001][4]={0};
for(int i=1;i<=n;i++){
for(int j=1;j<=3;j++){
if(j>i){
for(int k=j;k<=3;k++){
f[i][k]=f[i][j-1];
}
break;
}
bool bian=0;
if(a[i]!=j){
bian=1;
}
int last=j-1;
if(j-1<1) last=j;
int last2=j-2;
if(j-2<1) last2=j;
f[i][j]=mins(f[i-1][last]+bian,f[i-1][j]+bian);
f[i][j]=mins(f[i-1][last2]+bian,f[i][j]);
// cout<<f[i][j]<<" ";
}
// cout<<endl;
}
int ans=mins(mins(f[n][1],f[n][2]),f[n][3]);
int h[30001][4]={0};
for(int i=1;i<=n;i++){
// cout<<endl;
for(int j=3;j>=1;j--){
if(3-j+1>i){
for(int k=j;k>=1;k--){
h[i][k]=h[i][j-1];
}
break;
}
bool bian=0;
if(a[i]!=j){
bian=1;
}
int last=j+1;
if(j+1>3) last=j;
int last2=j+2;
if(j+2>3) last2=j;
h[i][j]=mins(h[i-1][last]+bian,h[i-1][j]+bian);
h[i][j]=mins(h[i-1][last2]+bian,h[i][j]);
// cout<<h[i][j]<<" ";
}
}
cout<<mins(mins(h[n][2],h[n][3]),mins(ans,h[n][1]));
}

BIN
2862_cow/main.exe Normal file

Binary file not shown.

6
2862_cow/test/in.txt Normal file
View File

@ -0,0 +1,6 @@
5
1
3
2
1
1

6
2862_cow/test/in2.txt Normal file
View File

@ -0,0 +1,6 @@
5
3
1
3
2
1

11
2862_cow/test/in3.txt Normal file
View File

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

18
2862_cow/test/out.txt Normal file
View File

@ -0,0 +1,18 @@
## z:\Chao\src\2862_cow\test\in.txt
2020/05/02 ÖÜÁù 21:37:42.79
1
-----------------------------------------------
Process exited after 150 ms with return value 0
## z:\Chao\src\2862_cow\test\in2.txt
2020/05/02 ÖÜÁù 21:37:42.79
1
-----------------------------------------------
Process exited after 100 ms with return value 0
## z:\Chao\src\2862_cow\test\in3.txt
2020/05/02 ÖÜÁù 21:37:42.79
1
-----------------------------------------------
Process exited after 100 ms with return value 0