AtCoder Beginner Contest 043

AtCoder Beginner Contest 043

A - Children and Candies (ABC Edit)

题意:

题解:

代码:

#include <bits/stdc++.h>

#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

inline int read() {
   int s = 0, w = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
   while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
   return s * w;
}

int const MAXN = 2e5 + 10;
int n, m, T;

signed main() {
    cin >> n;
    cout << (1 + n) * n / 2;
    return 0;
}

B - Unhappy Hacking (ABC Edit)

题意:

题解:

代码:

#include <bits/stdc++.h>

#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

inline int read() {
   int s = 0, w = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
   while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
   return s * w;
}

int const MAXN = 2e5 + 10;
int n, m, T;

signed main() {
    string s;
    cin >> s;
    stack<char> stk;
    for (int i = 0; i <s.size(); ++i  ) {
        if (s[i] != 'B') stk.push(s[i]);
        else  if (stk.size()) stk.pop();
    }
    string res = "";
    while(stk.size()) {
        res += stk.top();
        stk.pop();
    }
    reverse(res.begin(), res.end());
    cout << res;
    return 0;
}

C - Be Together

题意:

题解:

代码:

#include <bits/stdc++.h>

#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

inline int read() {
   int s = 0, w = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
   while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
   return s * w;
}

int const MAXN = 2e5 + 10;
int n, m, T;
int a[MAXN];

signed main() {
    cin >> n;
    int Min = 1e18, Max = -1e18;
    for (int i = 1; i <= n; ++i) cin >> a[i], Min = min(Min, a[i]), Max = max(Max, a[i]);
    int tmp_Min = 1e18;
    for (int i = Min; i <= Max; ++i) {
        int tmp = 0;
        for (int j = 1; j <= n; ++j) {
            tmp += (a[j] - i) * (a[j] - i);
        }
        tmp_Min = min(tmp_Min, tmp);
    }
    cout << tmp_Min;
    return 0;
}

D - Unbalanced

题意:

题解:

代码:

#include <bits/stdc++.h>

#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

inline int read() {
   int s = 0, w = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
   while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
   return s * w;
}

int const MAXN = 2e5 + 10;
int n, m, T;

signed main() {
    int s = -1, e = -1;
    int flg = 0;
    string ss;
    cin >> ss;
    for (int i = 0; i < ss.size(); ++i) {
        if (ss[i] == ss[i + 1]) {
            s = i, e = i + 1;
            flg = 1;
            break;
        }
        else if (ss[i] == ss[i + 2]) {
            s = i, e = i + 2;
            flg = 1;
            break;
        }
    }
    if (flg) cout << s + 1 << " " << e + 1 << endl;
    else cout << -1 << " " << -1 ;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值