11.25 AtCoder Beginner Contest 129

AtCoder Beginner Contest 129

A

水题

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, c;
    cin >> a>> b >> c;
    int ans = a+ b;
    ans = min(ans ,a + c);
    ans = min(ans, b + c);
    cout << ans << endl;
    return 0;
}

B

前缀和

const int MAXN = 105;
int a[MAXN];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int  n;
    cin >> n;
    int ans = 1e9+5;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) a[i] += a[i-1];
    for(int i = 1; i <= n; i++)
    {
        ans = min(ans, int(abs(a[i] - a[n] + a[i])));
    }
    cout << ans << endl;
    return 0;
}

C

变种fibonacci

const int MAXN = 1e5+5;
int vis[MAXN];
ll f[MAXN];
const int mod = 1e9+7;
int main()
{
    //FIN;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int m;
    cin >> m;
    for(int i = 0; i < m; i++)
    {
        int num;
        cin >> num;
        vis[num] = 1;
    }
    if(!vis[1]) f[1] = 1;
    f[0] = 1;
    for(int i = 2; i <= n; i++)
    {
        if(!vis[i-1]) f[i] += f[i-1];
        if(!vis[i-2]) f[i] += f[i-2];
        f[i] %= mod;
    }
    cout << f[n] << endl;
    return 0;
}

D

比赛的时候抽风
先预处理即可

string s[2010];
int a[2010][2010], b[2010][2010];
int numa[2010 * 2010], numb[2010 * 2010];
int main()
{
    int i, j, k, n, m, x, y, h = 0;
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    for (i = 0; i < n; i++)
    {
        x = 0;
        for (j = 0; j < m; j++)
        {
            if (s[i][j] == '#')
            {
                if (x > 0)
                {
                    numa[h] = x;
                    x = 0;
                    h++;
                }
            }
            else
            {
                a[i][j] = h;
                x++;
            }
        }
        if (x > 0)
        {
            numa[h] = x;
            h++;
        }
    }
    h = 0;
    for (i = 0; i < m; i++)
    {
        x = 0;
        for (j = 0; j < n; j++)
        {
            if (s[j][i] == '#')
            {
                if (x > 0)
                {
                    numb[h] = x;
                    x = 0;
                    h++;
                }
            }
            else
            {
                b[j][i] = h;
                x++;
            }
        }
        if (x > 0)
        {
            numb[h] = x;
            h++;
        }
    }
    int ma = 0;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
        {
            ma = max(ma, numa[a[i][j]] + numb[b[i][j]] - 1);
        }
    }
    printf("%d", ma);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值