头像

合计飞

中北大学




离线:8小时前


活动打卡代码 AcWing 754. 平方矩阵 II

合计飞
15小时前
#include<bits/stdc++.h>

using namespace std;
const int N = 110;

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

void _do(int i)
{
    int x = 1;
    a[i][i] = x;
    for(int l = i - 1, r = i + 1; l >= 0 || r < n; l --, r ++)
    {
        x ++;
        if(l >= 0) a[i][l] = x;
        if(r < n) a[i][r] = x;
    }
}

int main()
{
    while(cin >> n, n)
    {
        for(int i = 0; i < n; i ++)
            _do(i);
        for(int i = 0; i < n; i ++)
        {
            for(int j = 0; j < n; j ++)
                cout << a[i][j] << ' ';
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


活动打卡代码 AcWing 1341. 十三号星期五

#include<iostream>
#define YEAR 1900
using namespace std;

int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool rn(int y)
{
    if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) 
        return true;

    return false;
}
int n;
int ans[7];

int main()
{
    cin >> n;

    int x = 1;

    for(int i = 0; i < n; i ++)
    {
        for(int j = 0; j < 12; j ++)
        {
            int y = month[j];
            if(j == 1 && rn(YEAR + i)) y ++;

            for(int k = 1; k <= y; k ++)
            {
                if(k == 13) ans[x] ++;
                x = (x + 1) % 7;
            }
        }
    }
    cout << ans[6] << " " << ans[0];
    for(int i = 1; i < 6; i ++)
        cout << " " << ans[i];

    puts("");
    return 0;
}


活动打卡代码 AcWing 1532. 找硬币

#include<bits/stdc++.h>

using namespace std;
const int N = 100010;

int n, m;
int a[N];

int main()
{
    unordered_map<int, int> mp;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i ++)
    {
        scanf("%d", &a[i]);
        mp[a[i]] ++;
    }

    sort(a, a + n);

    int res = -1;
    for(int i = 0; i < n; i ++)
        if(mp.count(m - a[i]))
        {
            if(2 * a[i] == m && mp[a[i]] < 2) continue;
            res = a[i];
            break;
        }

    if(res == -1) puts("No Solution");
    else cout << res << ' ' << m - res << endl;
    return 0;
}


活动打卡代码 AcWing 1208. 翻硬币

#include<bits/stdc++.h>

using namespace std;

int main()
{
    string sta, end;
    cin >> sta >> end;
    vector<int> v;

    for(int i = 0; i < sta.size(); i ++)
        if(sta[i] != end[i])
            v.push_back(i);

    int res = 0;
    for(int i = 0; i < v.size(); i += 2)
        res += v[i + 1] - v[i];
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 429. 奖学金

#include<bits/stdc++.h>

using namespace std;
const int N = 310;

struct Node{
    int x, sum, k;
    bool operator < (Node& w)
    {
        if(sum != w.sum) return sum > w.sum;
        else if(x != w.x) return x > w.x;
        else return k < w.k;
    }
}st[N];

int n;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i ++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        st[i] = {x, x + y + z, i + 1};
    }

    sort(st, st + n);

    for(int i = 0; i < 5; i ++)
        cout << st[i].k << ' ' << st[i].sum << endl;

    return 0;
}


活动打卡代码 AcWing 422. 校门外的树

#include<bits/stdc++.h>

#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int M = 110;

int L, m;
PII a[M];

int main()
{
    cin >> L >> m;
    for(int i = 0; i < m; i ++)
        cin >> a[i].x >> a[i].y;
    sort(a, a + m);
    a[m] = {L + 10, L + 10};
    int res = L + 1;
    int sta = a[0].x, end = a[0].y;
    for(int i = 1; i <= m; i ++)
    {
        auto t = a[i];
        if(t.x <= end) end = max(end, t.y);
        else 
        {
            res -= end - sta + 1;
            sta = t.x;
            end = t.y;
        }
    }
    cout << res << endl;
    return 0;   
}


活动打卡代码 AcWing 1227. 分巧克力

#include<bits/stdc++.h>

#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 100010;

int n, k;
PII a[N];

bool check(int x)
{
    int res = 0;
    for(int i = 0; i < n; i ++)
    {
        auto t = a[i];
        res += (t.x / x) * (t.y / x);
    }
    return res >= k;
}

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; i ++)
        cin >> a[i].x >> a[i].y;

    int l = 1, r = N;
    while(l < r)
    {
        int mid = (l + r + 1) >> 1;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l << endl;
    return 0;
}


活动打卡代码 AcWing 680. 剪绳子

#include<bits/stdc++.h>

using namespace std;
const int N = 100010;

int n, m;
int a[N];

bool check(double x)
{
    int res = 0;
    for(int i = 0; i < n; i ++)
        res += a[i] / x;
    return res >= m;
}

int main()
{
    cin >> n >> m;
    for(int i = 0; i < n; i ++) cin >> a[i];

    sort(a, a + n);

    double l = 0, r = 1e9;
    while(r - l > 1e-6)
    {
        double mid = (l + r) / 2;

        if(check(mid)) l = mid;
        else r = mid;
    }
    printf("%.2f", l);
    return 0;
}


活动打卡代码 AcWing 1346. 回文平方

#include<bits/stdc++.h>

using namespace std;

int b;

char get(int x)
{
    if(x < 10) return x + '0';
    else return x + 'A' - 10;
}

string to_b(int x)
{
    string res = "";
    while(x)
    {
        res += get(x % b);
        x /= b;
    }
    reverse(res.begin(), res.end());
    return res;
}

bool check(string s)
{
    for(int i = 0, j = s.size() - 1; i < j; i ++, j --)
        if(s[i] != s[j]) return false;
    return true;
}

int main()
{
    cin >> b;

    for(int i = 1; i <= 300; i ++)
    {
        string x = to_b(i * i);
        if(check(x)) 
            cout << to_b(i) << ' ' << x << endl;
    }
    return 0;
}


活动打卡代码 AcWing 1113. 红与黑

合计飞
10天前
#include<bits/stdc++.h>

#define x first
#define y second
using namespace std;
const int N = 25;

int n, m, cnt;
char a[N][N];
bool st[N][N];
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

void print()
{
    for(int i = 0; i < m; i ++)
    {
        for(int j = 0; j < n; j ++)
            cout << a[i][j];
        cout << endl;
    }
}

void bfs(int x, int y)
{
    queue<pair<int, int>> q;
    q.push({x, y});
    st[x][y] = true;
    cnt ++;
    while(q.size())
    {
        auto t = q.front();
        q.pop();
        for(int i = 0; i < 4; i ++)
        {
            int xx = t.x + dx[i], yy = t.y + dy[i];
            if(xx >= 0 && xx < m && yy >= 0 && yy < n && a[xx][yy] != '#')
            {
                if(!st[xx][yy])
                {
                    cnt ++;
                    q.push({xx, yy});
                    st[xx][yy] = true;
                }
            }
        }
    }
}

int main()
{
    while(cin >> n >> m, n && m)
    {
        memset(st, 0, sizeof st);
        int x, y;
        for(int i = 0; i < m; i ++)
            for(int j = 0; j < n; j ++)
            {
                cin >> a[i][j];
                if(a[i][j] == '@')
                {
                    x = i;
                    y = j;
                }
            }
        cnt = 0;
        bfs(x, y);
        cout << cnt << endl;
    }
    return 0;
}