AtCoder Beginner Contest 045

AtCoder Beginner Contest 045

A - Trapezoids

题意:

题解:

代码:

#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, b, h;

signed main() {
    cin >> a >> b >> h;
    cout << (a + b) * h / 2;
    return 0;
}

B - Card Game for Three (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;
deque<char> q1, q2, q3;

signed main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) q1.push_back(s[i]);
    // puts("");
    cin >> s;
    for (int i = 0; i < s.size(); ++i) q2.push_back(s[i]);
    // puts("");
    cin >> s;
    for (int i = 0; i < s.size(); ++i) q3.push_back(s[i]);
    // puts("");
    int flg = 1;
    char op;
    while (1) {
        if (flg == 1) {
            if (q1.size() == 0) {
                cout << "A";
                return 0;
            }
            op = q1.front();
            q1.pop_front();
        } else if (flg == 2) {
            if (q2.size() == 0) {
                cout << "B";
                return 0;
            }
            op = q2.front();
            q2.pop_front();
        } else if (flg == 3) {
            if (q3.size() == 0) {
                cout << "C";
                return 0;
            }
            op = q3.front();
            q3.pop_front();
        }
        // cout << op << " ";
        if (op == 'a')
            flg = 1;
        else if (op == 'b')
            flg = 2;
        else if (op == 'c')
            flg = 3;
    }

    return 0;
}

C - Many Formulas

题意: 给定一个字符串S,可以在S的任意字符间填入+号,问所有情况的累加和。 1 < = ∣ S ∣ < = 10 1<=|S|<=10 1<=S<=10

题解: 发现S的长度为10,非常小,直接暴力枚举每个位置是否填入+,那么就是 2 10 ∗ 10 2^{10} * 10 21010。不是特别明白S才10??完全可以给更大的。

代码:

#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;
string s;

int get(int cnt, string s) {
    int tmp = s[0] - '0';
    int res = 0;
    for (int i = 0; i < s.size() - 1; ++i) {
        int op = cnt >> i & 1;
        if (op == 1) res += tmp, tmp = s[i + 1] - '0';
        else tmp = tmp * 10 + s[i + 1] - '0';
    }
    res += tmp;
    return res;
}

signed main() {
    cin >> s;
    int len = s.size();
    int res = 0;
    for (int i = 0; i < (1 << (len - 1)); ++i) {
        // cout << i << " " << get(i, s) << endl;
        res += get(i, s);
    }    
    cout << res;
    return 0;
}

D - Snuke’s Coloring

题意: 给定一个 H 行 W 列的矩形,再给定矩形上 N 个黑格子的坐标。对于每个 0≤j≤9 ,求出有多少个 3×3 的子矩阵包含有恰好 j 个黑格子。 3 < = H < = 1 0 9 , 3 < = W < = 1 0 9 , 0 < = N < = m i n ( 1 0 5 , H ∗ W ) , 1 < = a i < = H , 1 < = b i < = W , ( a i , b i ) ≠ ( a j , b j ) ( i ≠ j ) 3<=H<=10^9,3<=W<=10^9,0<=N<=min(10^5, H * W), 1<=a_i<=H, 1<=b_i<=W, (a_i,b_i) \neq (a_j, b_j) (i \neq j) 3<=H<=109,3<=W<=109,0<=N<=min(105,HW),1<=ai<=H,1<=bi<=W,(ai,bi)=(aj,bj)(i=j)

题解: 每个格子只会影响周围9个格子,所以对于每个黑色格子暴力枚举对应的9个格子。如果一个3 * 3 的格子被2个黑色格子枚举到,那么说明这个格子里面含义2个黑色格子。维护方格直接使用map即可。

代码:

#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;
typedef pair<int, int> PII;
map<PII, int> mp;
int cnt[100];

signed main() {
    cin >> n >> m >> T;
    for (int k = 1; k <= T; ++k) {
        int x, y;
        cin >> x >> y;
        for (int i = max((int)1, x - 2); i <= min(x, n - 2); ++i) {
            for (int j = max((int)1, y - 2); j <= min(y, m - 2); ++j) {
                mp[{i, j}]++;
            }
        }
    }
    for (auto m: mp) {
        cnt[m.second]++;
    }
    int all = (n - 2) * (m - 2);
    for (int i = 1; i <= 9; ++i) all -= cnt[i];
    cout << all << "\n";
    for (int i = 1;i <= 9; ++i) cout << cnt[i] << endl;
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值