11.19课堂总结

· · 个人记录

课堂总结

1.T670767 小田的同余

题意:让我们算出x,x满足2*x得到的值÷输入的数(m)得到的余数是1。输出x。

思路:

1.已知一个奇数m

2.2*x % m==1

3.m+1 ==2×x

下面是我的代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long m;
    cin>>m;
    cout<<(m+1)/2; 
    return 0;
}

AC代码:

 #include<bits/stdc++.h>
 #define ll long long
 #define endl '\n'
 using namespace std;
 int main()
 {
    //已知一个奇数m
    // 2*x % m==1
    // m+1 == 2*x
    ll m;
    cin>>m;
    cout<<(m+1)/2;
    return 0;
 }

2.T692543 排队买奶茶

题意:(就是让我们模拟排队的过程)1.1 x,表示学号为 x的学生站到了队尾 adt;2.2, 表示队头的学生离开,ai+1成为新的队头;若此时队伍里没有同学,输出"空的";3.3, 输出当前在队头的学生的学号 a dt;若此时队伍里没有同学,输出"空的";4.4, 输出此时在排队的同学有多少人;

思路: 用一个队列来模拟排队,按照操作来进行相应的处理。

下面是我的代码:

#include<bits/stdc++.h>
using namespace std;
queue<int>q;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x==1){
            int y;
            cin>>y;
            q.push(y); 
        }else if(x==2){
            if(q.empty()==1){
                cout<<"空的"<<endl;
            }else{
                q.pop(); 
            }
        }else if(x==3){
            if(q.empty()==1){
                cout<<"空的"<<endl;
            }else{
                cout<<q.front()<<endl; 
            }
        }else {
            cout<<q.size()<<endl;
        } 
    }
    return 0;
}

AC代码:

#include<bits/stdc++.h>
 #define ll long long
 #define endl '\n'
 using namespace std;
 queue<int>q;
 int main()
 {
    int n;
    cin>>n;
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int y;
            cin>>y;
            q.push(y);
        }
        else if(x==2)
        {
            if(q.size()==0)
            {
                cout<<"空的"<<endl;
            }
            else
            {
                q.pop();
            }
        }
        else if(x==3)
        {
            if(q.size()==0)
            {
T3
 T4
                cout<<"空的"<<endl;
            }
            else
            {
                cout<<q.front()<<endl;
            }
        }
        else
        {
            cout<<q.size()<<endl;
        }
    }
    return 0;
 }

3.T687165 小田当门卫(Easy Version)

题意: 每位游客都会在博物馆逗留 3600 秒的时间。

以每一个人的到访时间为止的 3600 秒内,博物馆里的游客一共有多少个人?

也就是说,需要统计 n 条信息,对于第 i 条信息,你需要统计有多少个人的到达时间 t p ​ 满足 t i ​ −3600<t p ​ ≤t i ​ 。

思路: 输入到达时间之后,并入队列,然后开始清人(将队伍中超过3600秒的人踢出),每次执行完之后并输出队列长度。

下面是我的代码:

没写出来😥

AC代码:

#include<bits/stdc++.h>
using namespace std;
queue<int>q;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;

    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        q.push(x);
        while(x-q.front()>=3600&&q.size()!=0){
            q.pop();
        }
        cout<<q.size()<<'\n';   
    }

    return 0;
}

课堂总结:

在做题熟练度上有待提升。