笔试强训Day20 动态规划 模拟

经此一役小红所向无敌

题目链接:A-经此一役小红所向无敌_牛客小白月赛37 (nowcoder.com)

思路:

水题 直接跟思路即可。

AC code:

#include<iostream>
using namespace std;
typedef long long LL;
LL a1,a2,b1,b2,t1,t2,sum;
int main()
{
	scanf("%lld%lld%lld%lld",&a1,&b1,&a2,&b2);
	t1 = b1 / a2;
	t2 = b2 / a1;
	if(b1 % a2)
	   t1++;
	if(b2 % a1)
	   t2++;
	sum = min(t1, t2) * (a1 + a2);
	if(t1 < t2)
	   sum += a2 * 10;
	if(t2 < t1)
	   sum += a1 * 10;
	printf("%lld\n", sum);
}

DP6 连续子数组最大和

题目链接:连续子数组最大和_牛客题霸_牛客网 (nowcoder.com)

思路:

每一点跟前面连不连续,两种状态 取最大值即可。

AC code:

#include <iostream>
using namespace std;
const int N = 2e5 + 10;
int dp[N];
int ans = -2e9,n;
int main() 
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
        scanf("%d",&dp[i]);
    for(int i = 1; i <= n; i ++)
    {   
        dp[i] = max(dp[i], dp[i] + dp[i - 1]);
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;
    return 0;
}

非对称之美

题目链接:I-非对称之美_牛客小白月赛31 (nowcoder.com)

思路:

模拟题 若给出的字符串为回文串 直接输出size -1;

不是 直接输出 size。

若字母全相同 特判输出0即可。

AC code:

#include<iostream>
#include<algorithm>
using namespace std;
string a,t;
int ans;
bool check(string a)
{
    for(auto& t : a)
        if(t != a[0])
            return 0;
    return 1;
}

int main()
{
    cin >> a;
    if(check(a))
    {
        cout << 0;
        return 0;
    }
    t = a;
    reverse(a.begin(), a.end());
    if(t == a) cout << a.size() - 1;
    else cout << a.size();
    return 0;
}

  • 14
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值