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

天梯赛练习题L2(026-027)

时间:2023-03-06 17:00:57浏览次数:45  
标签:练习题 typedef const LL long priority 027 026 return

###L2-026 小字辈

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=100020,M=4002;
//unordered_map<LL,LL> a[N];
//priority_queue<LL> pq;
//priority_queue<LL,vector<LL>,greater<LL>> pq2;
LL n,root=-1,maxn=1;
LL a[N];
vector<LL> res,v[N];
vector<PII> ans;
void dfs(LL x,LL last,LL depth)
{
    maxn=max(maxn,depth);
    if(v[x].size()==0)
    {
        ans.push_back({x,depth});
        return ;
    }
    for(int i=0;i<v[x].size();i++)
        dfs(v[x][i],x,depth+1);
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i]==-1) root=i;
            else v[a[i]].push_back(i);
        }
        dfs(root,-1,1);
        cout<<maxn<<endl;
        for(int i=0;i<ans.size();i++)
        {
            //cout<<ans[i].first<<" "<<ans[i].second<<endl;
            if(ans[i].second==maxn) //cout<<ans[i].first<<endl;
                res.push_back(ans[i].first);
        }
        sort(res.begin(),res.end());
        for(int i=0;i<res.size();i++)
        {
            if(i!=res.size()-1) cout<<res[i]<<" ";
            else cout<<res[i];
        }
    }
    return 0;
}

###L2-027 名人堂与代金券

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=10200,M=4002;
//unordered_map<LL,LL> a[N];
//priority_queue<LL> pq;
//priority_queue<LL,vector<LL>,greater<LL>> pq2;
LL n,m,k;
struct node
{
    string s;
    LL x,y=0;
    LL id;
}a[N];
bool cmp(node l,node r)
{
    if(l.x!=r.x) return l.x>r.x;
    else return l.s<r.s;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n>>m>>k;
        LL sum=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i].s>>a[i].x;
            if(a[i].x>=m) a[i].y=50;
            else if(a[i].x>=60) a[i].y=20;
            sum+=a[i].y;
        }
        sort(a+1,a+1+n,cmp);
        cout<<sum<<endl;
        LL last;
        for(int i=1;i<=n;i++)
        {
            if(i==1)
            {
                last=1;
                if(last>k) break;
                cout<<"1 "<<a[i].s<<" "<<a[i].x<<endl;
            }
            else
            {
                if(a[i].x==a[i-1].x) cout<<last<<" "<<a[i].s<<" "<<a[i].x<<endl;
                else
                {
                    last=i;
                    if(last>k) break;
                    cout<<last<<" "<<a[i].s<<" "<<a[i].x<<endl;
                }
            }
            if(last>k) break;
        }
    }
    return 0;
}

标签:练习题,typedef,const,LL,long,priority,027,026,return
From: https://www.cnblogs.com/Vivian-0918/p/17030966.html

相关文章

  • Uoj228 基础数据结构练习题
    Uoj228最开始好像是在那个区间加区间\(\text{popcount}\)的题里看到有人提到这个题,就来写下。离联合省选还有26天,发了一上午呆。题意区间加区间开根区间和\(n,......
  • 给闺女写了一个99乘法除法练习题
    #99乘法练习importrandomimporttimenum=0start=time.time()forxinrange(10):a=random.randint(1,9)b=random.randint(1,9)print('请小余同......
  • 又更新了 20 道 TS 练习题,你能答对几道?
    中秋假期已经结束了,由于疫情原因阿宝哥在家里待了三天,期间精选了 20 道新的TS练习题,目前已经有 30 道题了。很多小伙伴已提交了他们心目中的答案,撸过TS的小伙伴赶......
  • 分析总结一下所有有关打印题目的套路和思路:pat乙级:1109 擅长C, 1008元素循环右移,1050
    分析:首先你要明白第一件事:所有要打印东西的题目打印都是从第一行到最后一行,从第一列到最后一列,你是没办法跳着打印的。可以看看其他几个打印题目1008元素循环右移,1050螺......
  • [gym102769D]Defend City
    以下描述部分方向代指该方向的塔,建议画图理解不妨假设左下的塔数\(\ge2\),这些塔覆盖区域构成阶梯形考虑阶梯的交点,若其被左上/右下覆盖,则总可以去掉其中一个左下换言之......
  • Python笔记--练习题(都来瞧一瞧,看一看嘞)
    利用Python对文件进行操作重新写入的文件如下图所示:统计学生成绩文件的最高分最低分和平均分Python如何统计英文文章出现最多的单词Python统计目录下的文件大小......
  • vus.js代码027
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>事件绑定</title><scripttype="text/javascript"src="../js/vue.js"></script></head>......
  • vue.js代码026
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>事件绑定</title><scripttype="text/javascript"src="../js/vue.js"></script></head>......
  • 点分治练习题单(动态更新)
    传送门有点难,慢慢做。1.P2634[国家集训队]聪聪可可比板子要简单一点,分治时寻找路径时用桶记录模数为\(0,1,2\)的个数,再进行\(01\)背包即可。统计答案时由于两点可......
  • 树剖练习题题解总和(动态更新)
    这篇博客的练习题题解1、P3384【模板】轻重链剖分/树链剖分模板题,详见此#include<iostream>#include<cstdio>#include<vector>usingnamespacestd;intn,m,r,p,t[......