跳到正文

个人记录

11月19号周三晚上训练课总结

laura2014约 9 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 9 分钟

版本

  1. v2当前
  2. v1

题目标题: T670767 小田的同余

题意分析: 给出一个奇数M,找出一个整数X,使两个X÷M的余数是1,然后输出这个X。

思路: 输入一个奇数M,然后输出括号M+2÷2的商。

代码:

C++
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int main()
{
	ll m;
    cin>>m;
    cout<<(m+2)/2;
	return 0;
}

贴AC代码:

C++
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int main()
{
	ll m;
    cin>>m;
    cout<<(m+2)/2;
	return 0;
}

题目标题: T692543 排队买奶茶

题意分析: 编辑一个代码,模拟同学排队买奶茶的队伍。

思路: 输入一个N,表示有N个指令。指令1,那么安排一个同学站在队尾。指令2,站在对头的一个同学拿到奶茶后离开队伍。如果没有同学,那就输出空的。指令3,问,现在到哪位同学在队头输出同学生的学号,如果没有同学那么就输出空的指令四输出现在排队的有多少人。

代码:

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

老师后面给了一个提示改的。 贴AC代码:

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

错因: 循环变量里与输入的用的是一个变量。

题目标题: T687165 小田当门卫(Easy Version)

题意分析: 想要知道以每一个人的到访时间为止的3600秒内,博物馆里的游客一共有多少个人? 思路: 输入一个整数N表示游游客的数量,输入N个整数T表示每个游客到达的时间表,保证T是升序,将该时间加进队列开始清人。将队伍中超过3600秒的人踢出,最后输出现在的人数。

代码:

C++
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
queue<int>a;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n,x,s=0;
    cin>>n;
    while(n--)
    {
        cin>>x;
        a.push(x);
        while(a.size()!=0&&x-a.front()>=3600)
        {
            a.pop();
        }
        cout<<a.size()<<endl;
    }
	return 0;
}

后面补上的。 贴AC代码:

C++
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
queue<int>a;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n,x,s=0;
    cin>>n;
    while(n--)
    {
        cin>>x;
        a.push(x);
        while(a.size()!=0&&x-a.front()>=3600)
        {
            a.pop();
        }
        cout<<a.size()<<endl;
    }
	return 0;
}

题目标题: T671141 Large Queue

题意分析: 输出所有类型2操作后答案。

思路: 有Q个操作,如果是类型1,那么就输入1。和往一个序列A的末尾添加C个X,如果是类型2,就输入K和2,删除序列A的前K个元素。最后输出所有类型2操作后答案。

代码: 后面补上的。

C++
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
struct st
{
    ll g,z;
};
queue<st>a;
int main()
{
    ll n,x,y,z,k,s=0;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(x==1)
        {
            cin>>y>>z;
            a.push({y,z});
        }
        else
        {
            cin>>k;
            while(a.size()!=0&&k-a.front().g>=0)
            {
            s+=a.front().g*a.front().z;
                k-=a.front().g;
                a.pop();
            }
            s+=k*a.front().z;
            a.front().g-=k;
            cout<<s<<endl;
            s=0;
        }
    }
	return 0;
}

贴AC代码:

C++
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
struct st
{
    ll g,z;
};
queue<st>a;
int main()
{
    ll n,x,y,z,k,s=0;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(x==1)
        {
            cin>>y>>z;
            a.push({y,z});
        }
        else
        {
            cin>>k;
            while(a.size()!=0&&k-a.front().g>=0)
            {
            s+=a.front().g*a.front().z;
                k-=a.front().g;
                a.pop();
            }
            s+=k*a.front().z;
            a.front().g-=k;
            cout<<s<<endl;
            s=0;
        }
    }
	return 0;
}
原文