《看了受制了》第十七天,4道题,合计74道题

发布时间 2023-09-15 22:14:37作者: wxzcch

2023年9月15日

小白月赛前三题,PAT一题。这个PAT,我怕是读题都有困难啊。中文都读半天。。。。。

ACWIGN1494 银行排队

题目理解

这个题目就是模拟。纯模,数字字符串来回转。

代码实现

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N = 10010;
int n, k;

int num(char c)
{
    return (int)c - 48;
}

int get(string p)
{
    int h = 10 * num(p[0]) + num(p[1]);
    int m = 10 * num(p[3]) + num(p[4]);
    int s = 10 * num(p[6]) + num(p[7]);

    return h * 3600 + m * 60 + s;
}

pair<string, int> q[N];
int main()
{
    int is = 0;
    cin >> n >> k;

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

    sort(q + 1, q + 1 + n);

    priority_queue<int, vector<int>, greater<int>> qu;

    double total = 0;
    for(int i = 1; i <= n; i++)
    {
        double one = 0;
        string p = q[i].first;
        int last = q[i].second;
        if(last > 60)   
            last = 60;
        // 得到开始的时间秒数
        int se = get(p);
        if(se > 17 * 3600)
            break;
        is ++;
        int end = 0;

        // 开始要不要等,得到结束的秒数

        if(qu.size() < k)       // 没满
        {
            if(se < 8 * 3600)
            {
                one += 8 * 3600 - se;   // 只等待没开门
                end = 8 * 3600 + last * 60;
            }else{
                end = last * 60 + se;
            }
            qu.push(end);
        }else{  //满了

            int last_p = qu.top();    // 最先进去的顾客。出来的时间

            if(se < last_p)     // 如果是第一个顾客还没出来
            {
                one += last_p - se;
                end = last_p + last * 60;   //从上一个顾客出来再到结束
            }else{  //如果第一个顾客出来了

                end = se + last * 60;   //不需要等待直接进去
            }
            qu.push(end);
            qu.pop();   //要出来一个顾客了
        }

        total += one;

    }


    printf("%.1lf", total / 60 / is);
    return 0;
}

牛客月赛78第一题

题目理解

算面积。。。精度问题哎

代码实现

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
    double a, b;
    cin >> a >> b;
    
    double r = a + b;

    double s = r * r * 3.141592653589793;
    
    printf("%.10lf", s);
    
    return 0;
    
}

小白月赛78第二题

题目理解

简单的模拟题,进行模拟即可。遇到小于10要加1、0加2、能整除加1

代码实现

#include<iostream>
using namespace std;

int main()
{
    string s;
    cin >> s;
    
    int res = 0;
    int a = 0, b = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'a')
        {
            a++;
        }else
            b++;
        
        if(a == 0)
            res += 2;
        else if(a < 10)
            res += 1;
        else if(a % 10 == 0)
            res += 1;
            
        if(b == 0)
            res += 2;
        else if(b < 10)
            res += 1;
        else if(b % 10 == 0)
            res += 1;
    }
    cout << res;
    return 0;
}

小白月赛第三题

题目理解

对于这个集合中的一个数可以用,k1 * a + k2 * b来表示。学到的是set中的,rease操作。

代码实现

#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

const int N = 1e6 + 10;
int dp[N];
typedef long long ll;

int main()
{
    ll k, a, b;
    
    cin >> k >> a >> b;
    
    set<ll> s;
    
    ll last;
    
    s.insert(a);
    s.insert(b);
    while(k -- )
    {
        last = *s.begin();
        s.erase(s.begin());
        s.insert(last + a);
        s.insert(last + b);
    }
    cout << last;
    return 0;
}