ASoroban
打表题
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code#include <iostream>
#include <string>
using namespace std;
const string A[10]={"O-|-OOOO","O-|O-OOO","O-|OO-OO",
"O-|OOO-O","O-|OOOO-","-O|-OOOO",
"-O|O-OOO","-O|OO-OO","-O|OOO-O",
"-O|OOOO-"};
int main()
{
int n;
cin>>n;
if(n==0)cout<<A[0]<<endl;
while(n>0){
cout<<A[n%10]<<endl;
n/=10;
}
return 0;
}
BFence
前缀和。。。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code#include <iostream>
using namespace std;
const int N=150000;
int n,k,h[N+10];
int main()
{
cin>>n>>k;
h[0]=0;
int minnum=(n+1)*101,ans=1;
for(int i=1;i<=n;i++){
cin>>h[i];
h[i]+=h[i-1];
if((i>=k)&&(h[i]-h[i-k]<minnum)){
minnum=h[i]-h[i-k];
ans=i-k+1;
}
}
cout<<ans<<endl;
return 0;
}
CFixing Typos
唯一的动脑子题目还让我写费事了。。。。其实可以贪的。。。。。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code#include <iostream>
#include <string>
#include <cstdio>
#define one 0
#define two 1
using namespace std;
const int S=200000;
string s;
char A[S+10];
int B[S+10];
int f[S+10][2];
int main()
{
getline(cin,s);
int len=s.length(),p=0;
A[0]='!';B[0]=0;
for(int i=0;i<len;i++)
if(s[i]==A[p])
B[p]++;
else{
p++;
A[p]=s[i];
B[p]=1;
}
//for(int i=1;i<=p;i++)
// cout<<A[i]<<','<<B[i]<<endl;
f[0][0]=f[0][1]=0;
for(int i=1;i<=p;i++){
f[i][one]=min(f[i-1][one],f[i-1][two])+B[i]-1;
if(B[i]>=2)
f[i][two]=f[i-1][one]+B[i]-2;
else
f[i][two]=f[i-1][one];
}
//for(int i=1;i<=p;i++)cout<<B[i]<<',';cout<<endl;
//for(int i=1;i<=p;i++)cout<<f[i][one]<<',';cout<<endl;
//for(int i=1;i<=p;i++)cout<<f[i][two]<<',';cout<<endl;
for(int i=p;i>=1;i--){
if(f[i][two]<f[i][one]){
B[i]=2;
B[i-1]=1;
i--;
}
else{
B[i]=1;
}
}
for(int i=1;i<=p;i++)
for(int j=1;j<=B[i];j++)
cout<<A[i];
cout<<endl;
return 0;
}