Atcoder abc175(A~E)

本文详细解析了五道算法竞赛题目,包括最长连续字符计数、三角形组合计数、数值调整策略、矩阵路径最大值及动态规划应用,提供了完整的AC代码与解题思路。

比赛链接
A
题意
最长连续R有多少?
模拟即可
AC代码

#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
char s[4];
int main()
{
    cin>>s;
    int sum=0;
    for(int i=0;i<3;i++)
    {
        int x=0;
        if(s[i]=='R')
        {
            x++;
            while(s[i+1]=='R')
            {
                x++;
                i++;
            }
        }
        sum=max(sum,x);
    }
    cout<<sum<<endl;
    return 0;
}

B
题意:
给你N个长度
问 i<j<k并且ai!=aj!=ak时可以组成多少个三角形
思路:因为数据量较小所以暴力枚举即可
AC代码:

#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int a[120];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    sort(a,a+n);
    ll sum=0;
    for(int i=0; i<n; i++)
        for(int j=i+1; j<n; j++)
            for(int k=j+1; k<n; k++)
            {
                if(a[k]<a[j]+a[i]&&a[i]>a[k]-a[j]&&a[k]!=a[i]&&a[j]!=a[i]&&a[k]!=a[j])
                {
                    sum++;
                }
            }
    cout<<sum<<endl;
    return 0;
}

C
题意:
给你一个数N,可以执行K次操作,每次取N-D或者N+D,最后要求绝对值最小
思路:
判断N/D的次数和K的大小,如果sum>k则可以尽管减最终也不会为负数
这输出N-K*D,如果K>sum则判断K-sum后为偶数还是奇数
为奇数则输出D-N%D
为偶数则输出N%D
AC代码为:

#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
ll n,k,d;
int main()
{
    cin>>n>>k>>d;
    n=abs(n);
    ll sum=n/d;
    ll t=n%d;
    if(sum>k)
    {
        cout<<n-k*d<<endl;
    }
    else
    {
        int x=k-sum;
        if(x%2==0)
        {
            cout<<n%d<<endl;
        }
        else
        {
            cout<<d-n%d<<endl;
        }
    }
    return 0;
}

D
没写出来,赛后补
E
题意
一个矩形,要从(1,1)走到(r,c)只能走(i+1,j)或者(i,j+1)
每行最多拿3个
求到达(r,c)的最大值
思路
DP,dp[i][j][k]表示第i行第j列,这一行已经取了K个了
然后就是简单的dp了,具体过程看代码理解
AC代码:

#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
ll dp[3020][3020][5];
ll a[3020][3020];
int main()
{
    int r,c,k;
    cin>>r>>c>>k;
    for(int i=0; i<k; i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        a[x][y]=z;
    }
    for(int i=1; i<=r; i++)
    {
        for(int j=1; j<=c; j++)
        {
            if(j==1)
            {
                dp[i][j][3]=dp[i-1][1][3]+a[i][j];
                dp[i][j][2]=dp[i-1][1][3]+a[i][j];
                dp[i][j][1]=dp[i-1][1][3]+a[i][j];
                dp[i][j][0]=dp[i-1][1][3];
                continue ;
            }
            dp[i][j][0]=max(dp[i][j-1][0],dp[i-1][j][3]);
            for(int k=1; k<=3; k++)
            {
                dp[i][j][k]=max(dp[i][j-1][k],dp[i][j-1][k-1]+a[i][j]);
                dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][3]+a[i][j]);
            }

        }
    }
    cout<<dp[r][c][3]<<endl;
    return 0;
}

### AtCoder Contest ABC346 Problems and Information AtCoder Beginner Contest (ABC) 346 is a programming competition designed to challenge participants with various algorithmic problems. Each problem within the contest has specific constraints regarding time limits, memory usage, and expected outputs. For instance, one of the sample output formats provided shows how results should be structured when submitting solutions[^3]. The format typically includes multiple test cases where each case expects certain input parameters leading to predefined outcomes. In terms of difficulty levels, contests like these usually start from easier tasks labeled as A or B progressing towards more complex challenges marked by letters such as D or E. Participants are encouraged to solve all given questions but must adhere strictly to guidelines concerning code length restrictions not exceeding 16KB along with execution times capped at 1 second per task while ensuring that no more than 256MB RAM is utilized during processing phases. Regarding legal aspects related possibly indirectly through referencing court decisions on jurisdictional matters which might apply broadly across online platforms hosting coding competitions; however this particular citation does not directly pertain specifically here[^2]. #### Example Problem Description Consider an example problem statement similar in structure though not exact wording: Given a binary tree represented implicitly via array indices, determine whether it can be inverted so every left child becomes a right child and vice versa without altering node values themselves. This type of question would fall under graph theory concepts applied practically within competitive programming environments aimed primarily toward beginners yet still requiring solid understanding fundamental data structures including trees alongside bitwise operations potentially useful solving space-efficiently due limited resources specified earlier mentioned constraints[^1]. ```python def invert_tree(tree_arr): n = len(tree_arr) for i in range(n//2): opposite_index = ((i+1)*(-1))-1 if abs(opposite_index) <= n: temp = tree_arr[i] tree_arr[i] = tree_arr[opposite_index] tree_arr[opposite_index] = temp return tree_arr ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值