不高兴的津津

image

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

using namespace std;

int main()
{
    int maxv = -1, p;
    for (int i = 1; i <= 7; i ++ )
    {
        int a, b;
        cin >> a >> b;
        if (a + b > maxv)
        {
            maxv = a + b;
            p = i;
        }
    }

    if (maxv > 8) printf("%d\n", p);
    else puts("0");

    return 0;
}

花生采摘

image image

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

using namespace std;

typedef pair<int, int> PII;

const int N = 30;

int n, m, k;
int g[N][N];

PII get_max()
{
    PII r = {0, 0};

    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            if (g[r.first][r.second] < g[i][j])
                r = {i, j};

    return r;
}

int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            cin >> g[i][j];

    auto t = get_max();
    if (t.first * 2 + 1 > k) puts("0");
    else
    {
        int res = g[t.first][t.second];
        k -= t.first + 1;
        g[t.first][t.second] = 0;

        while (true)
        {
            auto r = get_max();
            int d = abs(r.first - t.first) + abs(r.second - t.second);

            if (d + r.first + 1 > k) break;
            if (!g[r.first][r.second]) break;
            res += g[r.first][r.second];
            g[r.first][r.second] = 0;
            k -= d + 1;
            t = r;
        }

        printf("%d\n", res);
    }

    return 0;
}

陶陶摘苹果

image

#include <iostream>
#include <algorithm>

using namespace std;

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

    int height;
    cin >> height;
    height += 30;

    int res = 0;
    for (int i = 0; i < 10; i ++ )
        if (a[i] <= height)
            res ++ ;

    cout << res << endl;

    return 0;
}

校门外的树

image

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

using namespace std;

const int N = 10010;

int n, m;
bool st[N];

int main()
{
    scanf("%d%d", &m, &n);
    while (n -- )
    {
        int l, r;
        scanf("%d%d", &l, &r);
        for (int i = l; i <= r; i ++ ) st[i] = true;
    }

    int res = 0;
    for (int i = 0; i <= m; i ++ )
        if (!st[i])
            res ++ ;

    printf("%d\n", res);

    return 0;
}

image

#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int, int> PII;

const int N = 110;

int n, m;
PII seg[N];

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

    for (int i = 0; i < n; i ++ ) cin >> seg[i].first >> seg[i].second;

    sort(seg, seg + n);

    int res = m + 1;
    int st = seg[0].first, ed = seg[0].second;
    for (int i = 1; i < n; i ++ )
        if (seg[i].first <= ed) ed = max(seg[i].second, ed);
        else
        {
            res -= ed - st + 1;
            st = seg[i].first, ed = seg[i].second;
        }

    res -= ed - st + 1;

    cout << res << endl;

    return 0;
}

接水问题

image

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

using namespace std;

const int N = 10010, M = 110;

int n, m;
int w[N];
int q[M];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i ++ ) scanf("%d", &w[i]);

    for (int i = 0; i < n; i ++ )
    {
        int t = 0;
        for (int j = 0; j < m; j ++ )
            if (q[j] < q[t])
                t = j;

        q[t] += w[i];
    }

    int res = 0;
    for (int i = 0; i < m; i ++ ) res = max(res, q[i]);

    cout << res << endl;

    return 0;
}

成绩

image

公交换乘

image

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

using namespace std;

const int N = 100010;

int n;
struct Ticket
{
    int time, price;
}q[N];
bool st[N];

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

    int res = 0;
    for (int i = 0, l = 0, r = 0; i < n; i ++ )
    {
        int type, price, time;
        scanf("%d%d%d", &type, &price, &time);
        if (type == 0)
        {
            q[r ++ ] = {time, price};
            res += price;
        }
        else
        {
            while (l < r && time - q[l].time > 45) l ++ ;

            bool success = false;
            for (int j = l; j < r; j ++ )
                if (!st[j] && q[j].price >= price)
                {
                    st[j] = true;
                    success = true;
                    break;
                }
            if (!success) res += price;
        }
    }

    printf("%d\n", res);

    return 0;
}

网络连接

#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <vector>

using namespace std;

bool check(string addr)
{
    vector<int> w(5, -1);
    sscanf(addr.c_str(), "%d.%d.%d.%d:%d", &w[0], &w[1], &w[2], &w[3], &w[4]);

    for (int i = 0; i < 5; i ++ )
    {
        if (w[i] < 0) return false;
        if (i < 4 && w[i] > 255) return false;
        if (i == 4 && w[i] > 65535) return false;
    }

    char str[100];
    sprintf(str, "%d.%d.%d.%d:%d", w[0], w[1], w[2], w[3], w[4]);
    return str == addr;
}

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

    unordered_map<string, int> hash;
    for (int i = 1; i <= n; i ++ )
    {
        string type, addr;
        cin >> type >> addr;
        if (type == "Server")
        {
            if (!check(addr)) puts("ERR");
            else if (hash.count(addr)) puts("FAIL");
            else
            {
                hash[addr] = i;
                puts("OK");
            }
        }
        else
        {
            if (!check(addr)) puts("ERR");
            else if (!hash.count(addr)) puts("FAIL");
            else cout << hash[addr] << endl;
        }
    }

    return 0;
}

小熊的果篮

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

using namespace std;

const int N = 200010;

int n;
int w[N], l[N], r[N], bl[N], br[N];

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

    int cnt = 0;
    for (int i = 1, last = n; i <= n; i ++ )
    {
        int j = i + 1;
        while (j <= n && w[j] == w[i]) j ++ ;
        for (int k = i; k < j; k ++ ) l[k] = k - 1, r[k] = k + 1;
        l[i] = j - 1, r[j - 1] = i;
        br[last] = j - 1, bl[j - 1] = last;
        i = last = j - 1;
        cnt ++ ;
    }

    int head = br[n];

    while (true)
    {
        int new_head = -1;
        for (int t = cnt, i = head; t; t --, i = br[i])
        {
            int k = r[i];
            printf("%d ", k);
            if (k != i)
            {
                r[l[k]] = r[k], l[r[k]] = l[k];
                if (new_head == -1) new_head = i;
            }
            else
            {
                br[bl[k]] = br[k], bl[br[k]] = bl[k];
                cnt -- ;
            }
        }

        if (!cnt) break;
        head = new_head;

        if (cnt > 1)
        {
            new_head = -1;
            for (int t = cnt, i = head; t > 1; t --, i = br[i])
            {
                int j = br[i];
                if (w[i] == w[j])
                {
                    int ri = r[i], rj = r[j];
                    r[i] = rj, l[rj] = i;
                    l[ri] = j, r[j] = ri;
                    br[bl[i]] = br[i], bl[br[i]] = bl[i];
                    cnt -- ;
                }
                else if (new_head == -1) new_head = i;
            }
            if (new_head == -1) new_head = bl[head];
            head = new_head;
        }

        puts("");
    }

    return 0;
}

乘方

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

using namespace std;

typedef long long LL;

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);

    LL res = 1;
    while (a > 1 && b -- )
    {
        res *= a;
        if (res > 1e9)
        {
            res = -1;
            break;
        }
    }

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

0 条评论

目前还没有评论...

信息

ID
483
时间
1000ms
内存
256MiB
难度
(无)
标签
(无)
递交数
0
已通过
0
上传者