5.22周五下午--河东--蒋

· · 个人记录

P1042 [NOIP 2003 普及组] 乒乓球

错误原因:

最后没把多余的比输出 ,且只又刚好打完满足分制的比赛才会输出 。

代码:

#include<bits/stdc++.h>

using namespace std;

string s;

int main()
{
    char c;

    while(cin >> c)
    {
        if(c == 'E')
        {
            break;
        }

        s += c;
    }   

    while(cin >> c) { }

    int a = 0, b = 0;

    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'W')
        {
            a++;
        }
        else if(s[i] == 'L')
        {
            b++;
        }

        if((a == 11 || b == 11) && abs(a - b) >= 2)
        {
            cout << a << ":" << b << "\n";
            a = 0, b = 0; 
        }
    } 

    if(a != 0 && b != 0)
    {
        cout << a << ":" << b << "\n";
    }

    cout << "\n";

    a = 0, b = 0;

    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'W')
        {
            a++;
        }
        else if(s[i] == 'L')
        {
            b++;
        }

        if((a == 21 || b == 21) && abs(a - b) >= 2)
        {
            cout << a << ":" << b << "\n";
            a = 0, b = 0; 
        }
    } 

    if(a != 0 && b != 0)
    {
        cout << a << ":" << b << "\n";
    }
    return 0;
}

B3784 [语言月赛202306] 演唱会

错误原因:

没有关闭同步流 。

代码:

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e5 + 5; 

int n, m, a, b;

struct Node
{
    int x, y;
}sum[N];

bool cmp(Node s1, Node s2)
{
    return s1.x > s2.x;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m >> a >> b;

    int o = 0;

    for(int i = 1; i <= a; i++)
    {
        int cnt = 0, id = 0;

        for(int j = 1; j <= n; j++)
        {
            int x;
            cin >> x;
            sum[j].x += x;
            sum[j].y = j; 

            if(cnt < x)
            {
                cnt = x;
                id = j;
            }
        }

        if(i == b)
        {
            o = id;
        }
    }

    sort(sum + 1, sum + 1 + n, cmp);

    bool v = 0;

    for(int i = 1; i <= m; i++)
    {
        if(sum[i].y == o)
        {
            v = 1;
            sum[i].x = -1e9;
        }
    }


    if(v == 1)
    {
        cout << o << " ";

        for(int i = 1; i <= m; i++)
        {
            if(sum[i].x == -1e9)
            {
                continue;
            }
            else
            {
                cout << sum[i].y << " ";
            }
        }
    }
    else
    {
        for(int i = 1; i < m; i++)
        {
            cout << sum[i].y << " ";
        }

        cout << o << " ";
    }
    return 0;
}

T762530 【pty2022】大富翁

错误原因:

就是把他超过 l 个格子时直接模了 l ,但我的格子是从一开始的 ,所以就错了 。还有累加金币的时候 ,我每次只加了一 ,二题目要加 a_i 。

代码:

#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n, l, m, e, a[N], b[N], u[N];

struct Node
{
    int i, x, j, n;
};
queue<Node> q;

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

    for(int i = 1; i <= l; i++)
    {
        cin >> a[i];
    }

    for(int i = 1; i <= m; i++)
    {
        cin >> b[i];
    }

    for(int i = 1; i <= n; i++)
    {
        q.push({i, 1, 0, e});
        u[i] = 0;
    }

    for(int i = 1; i <= m; i++)
    {
        Node c = q.front();

        if(c.n <= 0)
        {
            q.pop();
            continue;
        }

        int o = c.x + b[i];
        o %= l;

        int l2 = i;

        if(a[o] == 0)
        {
            while(a[o] == 0 && l2 < m)
            {
                l2++;
                o += b[l2];
                o %= l;
            }

            if(a[o] == 0)
            {
                break;
            }
        }

        if(a[o] > 0)
        {
            q.pop();
            q.push({c.i, o, c.j + a[o], c.n});
            u[c.i] += a[o];
        }
        else
        {
            q.pop();
            if(c.n > abs(a[o + 1]))
            {
                q.push({c.i, o, c.j, c.n + a[o]});
            }
        }

        i = l2;
    }

    for(int i = 1; i <= n; i++)
    {
        cout << u[i] << " ";
    }
    return 0;
}