寒假限时训练(1)P、Q、R

· · 个人记录

寒假限时训练(1)P、Q、R

P - 手机


//这题出题人说太简单了,不用给代码了

Q - 乒乓球

#include <bits/stdc++.h>
using namespace std;
char c;
const int N = 1e6 + 10;
int a[N];
int k;
int win;
int lose;
int main()
{
    while (cin >> c && c != 'E')
    {
        if (c == 'W')
            a[k] = 1;
        else
            a[k] = 2;
        k++;
    }
    for (int i = 0;; i++)
    {
        if (a[i] == 1)
            win++;
        if (a[i] == 2)
            lose++;
        if (abs(win - lose) >= 2)
        {
            if (win >= 11 || lose >= 11) //切记切记 大于11!!
            {
                cout << win << ":" << lose << endl;
                win = 0; //进行下一轮比赛
                lose = 0;
            }
        }
        if (a[i] == 0)
        {
            cout << win << ":" << lose << endl;
            break;
        }
    }
    cout << endl;
    win = 0, lose = 0;
    for (int i = 0;; i++)
    {
        if (a[i] == 1)
            win++;
        if (a[i] == 2)
            lose++;
        if (abs(win - lose) >= 2)
        {
            if (win >= 21 || lose >= 21)
            {
                cout << win << ":" << lose << endl;
                win = 0; //进行下一轮比赛
                lose = 0;
            }
        }
        if (a[i] == 0)
        {
            cout << win << ":" << lose << endl;
            break;
        }
    }
    return 0;
}

R - Queue

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
    int n,ans=1;
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    int time=a[0];
    for(int i=1; i<n; i++)
    {
        if(time>a[i])
            continue; //如果这个人失望了,那么我们直接给他忽略掉,不服务他,因为为了使失望的人数最少,他已经失望了,我们只能让后面的人尽量少的失望

        else
        {
            ans++;
            time+=a[i];
        }

    }
    cout<<ans<<endl;
    return 0;
}