文章目录
- BC64 牛牛的快递
- DP4 最小花费爬楼梯
- [编程题]数组中两个字符串的最小距离
BC64 牛牛的快递
BC64 牛牛的快递
#include<iostream>
#include<cmath>
using namespace std;
double a;
char b;
int main()
{
cin>>a>>b;
int ans=0;
if(a<=1.0)
{
ans+=20;
}
else
{
ans+=20;
a-=1;
ans+=ceil(a);
}
if(b=='y') ans+=5;
cout<<ans<<endl;
return 0;
}
DP4 最小花费爬楼梯
DP4 最小花费爬楼梯
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int n;
int main()
{
cin>>n;
vector<int> a(n),dp(n+2);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=2;i<=n;i++)
{
dp[i]=min(dp[i-1]+a[i-1],dp[i-2]+a[i-2]);
}
cout<<dp[n]<<endl;
return 0;
}
[编程题]数组中两个字符串的最小距离
[编程题]数组中两个字符串的最小距离
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string s1, s2;
string s;
cin >> n;
cin >> s1 >> s2;
int prev1 = -1, prev2 = -1, ret = 0x3f3f3f3f;
for (int i = 0; i < n; i++)
{
cin >> s;
if (s == s1) // 去前⾯找最近的 s2
{
if (prev2 != -1)
{
ret = min(ret, i - prev2);
}
prev1 = i;
}
else if (s == s2) // 去前⾯找 s1
{
if (prev1 != -1)
{
ret = min(ret, i - prev1);
}
prev2 = i;
}
}
if (ret == 0x3f3f3f3f) cout << -1 << endl;
else cout << ret << endl;
return 0;
}