AtCoder Beginner Contest 237

A

#include <bits/stdc++.h>
#define int long long
using namespace std;
int T, n, m;
signed main() {
    cin >> n;
    int a = 2147483648;
    int b = a * -1;
    a --;
    if (n >= b && n <= a)   cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

B

#include <bits/stdc++.h>
using namespace std;
int T, n, m;
int main() {
    cin >> n >> m;
    vector<vector<int>> a(n + 1, vector<int>(m + 1)), b(m + 1, vector<int>(n + 1));
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            cin >> a[i][j];
    for (int i = 1; i <= m; i ++ )
        for (int j = 1; j <= n; j ++ )
            b[i][j] = a[j][i];
    for (int i = 1; i <= m; i ++ ) {
        for (int j = 1; j <= n; j ++ )
            cout << b[i][j] << " ";
        cout << endl;
    }
    return 0;
}

C

#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int main() {
    cin >> s + 1;
    int n = strlen(s + 1);
    int pos = strlen(s + 1);
    int start = 1;
    while (start <= n && s[start] == 'a')   start ++;
    while (pos && s[pos] == 'a') pos --;
    bool flag = 1;
    int len1 = start - 1, len2 = n - pos;
    while (start < pos) {
        if (s[start] != s[pos]) {
            flag = 0;
            break;
        }
        start ++, pos --;
    }
    if (flag && len2 >= len1)   cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

D

#include <bits/stdc++.h>
using namespace std;
int T, n, m;
char s[500010];
int main() {
    cin >> n;
    cin >> s + 1;
    deque<int> q;
    q.push_back(n);
    for (int i = n; i >= 1; i -- ) {
        if (s[i] == 'L')
            q.push_back(i - 1);
        else
            q.push_front(i - 1);
    }
    for (int i = 0; i < q.size(); i ++ )
        cout << q[i] << " ";
    cout << endl;
    return 0;
}

E
spfa跑最长路

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, M = N * 2;
int n, m, res;
int g[N], dist[N];
bool st[N];
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int c)
{
    e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx ++;
}
void spfa()
{
    memset(dist, 0xcf, sizeof dist);
    dist[1] = 0;
    queue<int> q;
    q.push(1);
    st[1] = true;
    while (q.size())
    {
        auto t = q.front();
        q.pop();
        st[t] = false;
        for (int i = h[t]; i != -1; i = ne[i])
        {
            int j = e[i];
            if (dist[j] < dist[t] + w[i])
            {
                dist[j] = dist[t] + w[i];
                if (!st[j])     
                {
                    q.push(j);
                    st[j] = true;
                }
            }
        }
    }
}
int main() {
    memset(h, -1, sizeof h);
    cin >> n >> m;
    for (int i = 1; i <= n; i ++ )  cin >> g[i];
    while (m -- ) {
        int a, b;
        cin >> a >> b;
        if (g[a] > g[b])    {add(a, b, g[a] - g[b]); add(b, a, 2 * (g[b] - g[a]));}
        else if (g[a] < g[b]) {add(a, b, 2 * (g[a] - g[b])); add(b, a, g[b] - g[a]);}
        else {add(a, b, 0); add(b, a, 0);}
    }
    spfa();
    for (int i = 1; i <= n; i ++ ) {
        if (dist[i] == 0xcfcfcfcf)  dist[i] = -1;
        res = max(res, dist[i]);
    }
    cout << res << endl;
    return 0;
}
posted @ 2022-01-31 10:26  Angels_of_Death  阅读(71)  评论(0)    收藏  举报