首页 > 其他分享 >天梯赛练习题L2(031-035)

天梯赛练习题L2(031-035)

时间:2023-01-22 19:33:08浏览次数:36  
标签:练习题 typedef const int LL cin long L2 031

L2-031 深入虎穴

这个题目我疑惑了好久,因为它说只有一个入口,但是却没有告诉我们哪个是入口,并且需要我们找出距离入口最远的那扇门
所以我们在做题时要一一判断哪个是入口,然后再进行寻找

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5e5+10,M=4002;
#define endl '\n'
LL n,maxn=0,ans=0,last[N];
vector<LL> v[N];
void dfs(LL idx,LL fa,LL dep)
{
    if(dep>maxn)
    {
        maxn=max(maxn,dep);
        ans=idx;
    }
    for(int i=0;i<v[idx].size();i++)
    {
        if(v[idx][i]==fa) continue;
        else dfs(v[idx][i],idx,dep+1);
    }
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        memset(last,-1,sizeof last);
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            LL op;
            cin>>op;
            for(int j=1;j<=op;j++)
            {
                LL x;
                cin>>x;
                v[i].push_back(x);
                last[x]=i;
            }
       }
       for(int i=1;i<=n;i++)
       {
           if(last[i]==-1)
           {
               dfs(i,-1,1);
           }
       }
       cout<<ans<<endl;
    }
    return 0;
}

L2-032 彩虹瓶

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5e5+10,M=4002;
#define endl '\n'
LL n,m,k,a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n>>m>>k;
        while(k--)
        {
            for(int i=1;i<=n;i++)
                cin>>a[i];
            stack<int> s;
            LL idx=1;
            bool flag=true;
            for(int i=1;i<=n;i++)
            {
                if(a[i]==idx)
                {
                    idx++;
                    while(!s.empty())
                    {
                        if(s.top()==idx)
                        {
                            s.pop();
                            idx++;
                        }
                        else break;
                    }
                }
                else
                {
                    s.push(a[i]);
                    if(s.size()>m)
                    {
                        flag=false;
                        break;
                    }
                }
            }
            //cout<<idx<<endl;
            if(flag==false||idx!=n+1) cout<<"NO"<<endl;
            else cout<<"YES"<<endl;
        }
    }
    return 0;
}

L2-033 简单计算器

仔细看懂题目解释的运算顺序即可

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=1000200,M=4002;
const double PI=3.1415926535;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        stack<LL> s;
        for(int i=1;i<=n;i++)
        {
            LL x;
            cin>>x;
            s.push(x);
        }
        stack<char> st;
        for(int i=1;i<=n-1;i++)
        {
            char c;
            cin>>c;
            st.push(c);
        }
        while(s.size())
        {
            LL a=s.top(); s.pop();
            LL b=s.top(); s.pop();
            char op=st.top(); st.pop();
            if(op=='+') s.push(b+a);
            else if(op=='-') s.push(b-a);
            else if(op=='*') s.push(b*a);
            else if(op=='/')
            {
                if(a==0)
                {
                    cout<<"ERROR: "<<b<<"/"<<a;
                    break;
                }
                else s.push(b/a);
            }
            if(s.size()==1)
            {
                cout<<s.top();
                break;
            }
        }
    }
    return 0;
}

L2-034 口罩发放

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=1e4+10,M=4002;
#define endl '\n'
LL d,p,t,s,anscnt;
map<string,LL> mp,vis;
struct node
{
	string name,id;
	LL flag;
	LL hh,mm,t;
	LL idx;
}a[N],ans[N];
bool cmp(node x,node y)
{
	if(x.t!=y.t) return x.t<y.t;
	return x.idx<y.idx;
}
bool check(string s)
{
	LL len=s.length();
	if(len!=18) return false;
	for(int i=0;i<len;i++)
    {
		if(!isdigit(s[i])) return false;
	}
	return true;
}
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>d>>p;
	    for(int i=1;i<=d;i++)//d天的数据
        {
            cin>>t>>s;//第i天:t条申请,s个发放名额
		    for(int j=1;j<=t;j++)
		    {
		        //姓名、身体状况、身体情况、提交时间
		        cin>>a[j].name>>a[j].id>>a[j].flag;
			    scanf("%d:%d",&a[j].hh,&a[j].mm);
			    a[j].t=a[j].hh*60+a[j].mm;
			    a[j].idx=j;//标记排名
			    if(mp.find(a[j].id)==mp.end()) mp[a[j].id]=0;
			    if(a[j].flag==1&&check(a[j].id)&&vis.find(a[j].id)==vis.end())
                {
                    vis[a[j].id]=0;
				    ans[anscnt++]=a[j];
			    }
            }
		    sort(a+1,a+t+1,cmp);
		    LL cnt=0;
		    for(int j=1;j<=t&&cnt<s;j++)
            {
                if(check(a[j].id)&&(!mp[a[j].id]||(i-mp[a[j].id])>p))
                {
                    cout<<a[j].name<<" "<<a[j].id<<endl;
				    cnt++;
				    mp[a[j].id]=i;
                }
            }
	    }
	    for(int i=0;i<anscnt;i++)
            cout<<ans[i].name<<" "<<ans[i].id<<endl;
    }
    return 0;
}

L2-035 完全二叉树的层序遍历

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5e5+10,M=4002;
#define endl '\n'
LL n,a[N];
void check(int i)
{
     if(i>n) return;
     check(2*i);
     check(2*i+1);
     cin>>a[i];
 }
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n;
        check(1);
        for(int i=1;i<=n;i++)
        {
            if(i!=n) cout<<a[i]<<" ";
            else cout<<a[i];
        }
    }
    return 0;
}

标签:练习题,typedef,const,int,LL,cin,long,L2,031
From: https://www.cnblogs.com/Vivian-0918/p/17059615.html

相关文章

  • SQL260 牛客每个人最近的登录日期(一)
    题目描述请你统计一下牛客每个用户最近登录是哪一天。有一个登录(login)记录表,请你写出一个sql语句查询每个用户最近一天登录的日子,并且按照user_id升序排序思路每个......
  • wsl2 参考的对象类型不支持尝试的操作
    原因使用代理软件,或游戏加速服务,winsock出现问题。可以通过注册表的方式,从winsock中排除wsl即可新增注册表信息新建.reg后缀的文本文件,内容为WindowsRegistryE......
  • 通过WSL2在Windows11环境下运行Xilinx ISE 14.7
    引言最近我开始学习FPGA,但是软件配置上就折腾了好久,所以通过这篇文章记录一下Win11下ISE的安装流程。开始我按照入门教程安好了Vivado打算开始愉快的学习,结果发现...我买......
  • 网络流24题(wll24)
    Howtobuildamap?byCiaxin大体概括网络流和线性规划24题中23道的模型与建图思路,以下所有的题目的思路均会向图论方向靠近。目录目录Howtobuildamap?目录#......
  • 【luogu AGC031E】Snuke the Phantom Thief(网络流)
    SnukethePhantomThief题目链接:luoguAGC031E题目大意有n个特殊点分布在二维平面上,每个点有坐标和价值。你要选一些点,总价值是你选的点的价值和。然后有一些约束,......
  • LibreOJ L2056 「TJOI / HEOI2016」序列
    https://loj.ac/p/2056CDQ优化DP模板?首先定义对于第\(x\)个数其可以变为的最小值为\(Min_x\),最大值为\(Max_x\),初始为\(M_x\)。因为最多只会变一次数,不难想到......
  • SQL258 找到每个人的任务
    题目描述有一个person表,主键是id,有一个任务(task)表如下,主键也是id请你找到每个人的任务情况,并且输出出来,没有任务的也要输出,而且输出结果按照person的id升序排序思路......
  • SQL256 出现三次以上相同积分的情况
    题目描述积分(grade)表,id为用户主键id,number代表积分情况,让你写一个sql查询,积分表里面出现三次以及三次以上的积分,查询结果注意:若有多个符合条件的number,则按number升......
  • SQL239 将titles_test表名修改为titles_2017
    SQL239将titles_test表名修改为titles_2017题目描述将titles_test表名修改为titles_2017。思路关于MySQL中ALTERTABLE的命令用法ALTERTABLE表名ADD列名/索引/......
  • win10 docker desktop wsl2
    现在(2023年1月15日),在win10系统上使用docker,最好的搭配就是wsl2子系统+dockerdesktop的wsl2basedenginedockerdesktop可以在win10系统上安装,较新版本的dockerdesk......