头像

Bug_FreeOωO

$ {\color {orange} {\Large{\mathit {AcWing\ University} }} }$




离线:3小时前


活动打卡代码 AcWing 3203. 画图

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 110;

int n;
bool st[N][N];

int main()
{
    cin >> n;
    while (n -- )
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        for (int i = x1; i < x2; i ++ )
            for (int j = y1; j < y2; j ++ )
                st[i][j] = true;
    }
    int res = 0;
    for (int i = 0; i < N; i ++ )
        for (int j = 0; j < N; j ++ )
            if (st[i][j])
                res ++ ;
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 3208. Z字形扫描

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 510;

int n;
int a[N][N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= n; j ++ )
            scanf("%d", &a[i][j]);

    for (int i = 2; i <= n * 2; i ++ )
    {
        if (i % 2)
        {
            for (int j = 1; j < i; j ++ )
                if (j >= 1 && j <= n && i - j >= 1 && i - j <= n)
                    printf("%d ", a[j][i - j]);
        }
        else
        {
            for (int j = i - 1; j; j -- )
                if (j >= 1 && j <= n && i - j >= 1 && i - j <= n)
                    printf("%d ", a[j][i - j]);
        }
    }

    return 0;
}



活动打卡代码 AcWing 1477. 拼写正确

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    string num;
    cin >> num;
    int sum = 0;
    for (auto c: num) sum += c - '0';

    string str = to_string(sum);
    string name[] = {
        "zero", "one", "two", "three", "four",
        "five", "six", "seven", "eight", "nine"
    };

    for (auto c: str)
        cout << name[c - '0'] << ' ';
    return 0;
}


活动打卡代码 AcWing 445. 数字反转

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    string str;
    cin >> str;

    reverse(str.begin(), str.end());
    if (str.back() == '-')
    {
        cout << '-';
        str.pop_back();
    }

    int k = 0;
    while (k + 1 < str.size() && str[k] == '0') k ++ ;
    while (k < str.size()) cout << str[k ++ ];
    return 0;
}


活动打卡代码 AcWing 449. 质因数分解

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int p = 2; ; p ++ )
        if (n % p == 0)
        {
            cout << n / p << endl;
            break;
        }
    return 0;
}


活动打卡代码 AcWing 441. 数字统计

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 10010;

int main()
{
    int l, r;
    cin >> l >> r;

    int res = 0;
    for (int i = l; i <= r; i ++ )
        for (int j = i; j; j /= 10)
            if (j % 10 == 2)
                res ++ ;

    cout << res << endl;

    return 0;
}


活动打卡代码 AcWing 3205. 最优配餐

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const int N = 1010, M = N * N;

int n, m, k, d;
bool g[N][N];
int dist[N][N];
queue<PII> q;
PII targets[M];
int sum[M];

void bfs()
{
    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

    while (q.size())
    {
        PII t = q.front();
        q.pop();

        for (int i = 0; i < 4; i ++ )
        {
            int x = t.x + dx[i], y = t.y + dy[i];
            if (x < 1 || x > n || y < 1 || y > n || g[x][y]) continue;
            if (dist[x][y] > dist[t.x][t.y] + 1)
            {
                dist[x][y] = dist[t.x][t.y] + 1;
                q.push({x, y});
            }
        }
    }
}

int main()
{
    scanf("%d%d%d%d", &n, &m, &k, &d);

    memset(dist, 0x3f, sizeof dist);
    while (m -- )
    {
        int x, y;
        scanf("%d%d", &x, &y);
        q.push({x, y});
        dist[x][y] = 0;
    }

    for (int i = 0; i < k; i ++ )
        scanf("%d%d%d", &targets[i].x, &targets[i].y, &sum[i]);
    while (d -- )
    {
        int x, y;
        scanf("%d%d", &x, &y);
        g[x][y] = true;
    }

    bfs();

    LL res = 0;
    for (int i = 0; i < k; i ++ )
        res += dist[targets[i].x][targets[i].y] * sum[i];

    printf("%lld\n", res);
    return 0;
}


活动打卡代码 AcWing 3195. 有趣的数

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;
const int N = 1010, MOD = 1e9 + 7;

int n;
int C[N][N];

int main()
{
    cin >> n;
    for (int i = 0; i <= n; i ++ )
        for (int j = 0; j <= i; j ++ )
            if (!j) C[i][j] = 1;
            else C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;

    int res = 0;
    for (int k = 2; k <= n - 2; k ++ )
        res = (res + (LL)C[n - 1][k] * (k - 1) % MOD * (n - k - 1)) % MOD;

    cout << res << endl;
    return 0;
}



// N+1 座建筑, 编号0 - N
// 机器人在 第 K 个建筑, 现在的能量值是E
// 如果 H(k+1)>E  E = H(k+1)-E or 0
// else  E >= H(k+1)  E = 2E-h(k+1)  E = 2E - h(k+1) 一样的
// 游戏目标是到达 第 N 个建筑(最后一个建筑)  E不能<0(E>=0)
// 求机器人最少需要多少能量值才可以完成游戏

#include <iostream>

const int N = 1e5 + 10;

int h[N];
int n;

bool check(int x)
{
    for(int i = 1; i <= n; i++)
    {
        x = 2 * x - h[i];
        if(x >= 1e5) return true;
        if(x < 1) return false;
    }
    return true;
}

int main(void)
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &h[i]); // h[1]-h[N];
    // E最大可以1e5 那么这样他就必然>=h[i]   1<=h[i]<=1e5  E最少需要1
    int l = 1, r = 1e5;
    while(l < r)
    {
        int mid = l + r >> 1;
        if(check(mid))
            r = mid;
        else
            l = mid + 1;
    }
    printf("%d\n", l);
    return 0;
}



活动打卡代码 AcWing 507. 积木大赛

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;

    int res = 0, last = 0;
    while (n -- )
    {
        int h;
        cin >> h;
        if (h > last) res += h - last;
        last = h;
    }
    cout << res << endl;
    return 0;
}