首页 > 其他分享 >西南民族大学 春季 2023 训练赛 8

西南民族大学 春季 2023 训练赛 8

时间:2023-04-18 22:14:36浏览次数:58  
标签:typedef const int cin 春季 训练赛 long 2023 tie

西南民族大学 春季 2023 训练赛 8

吃火锅

思路:每行只算一个(*^*)

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e2+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-8;
typedef long long ll;
int all,p,a;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    
    string b="chi1 huo3 guo1";
    while(1){
        string s;
        getline(cin,s);
        if(s==".")break;
        all++;
        int t;
        t=s.find(b);
        if(t!=-1){
            if(a==0)p=all;
            a++;
        }
    }
    cout<<all<<'\n';
    if(a==0)cout<<"-_-#";
    else cout<<p<<' '<<a;
    return 0;
}
View Code

 

前世档案

思路:

1.左子树 (*2),右子树 (*2+1),减去2^n即为结论数 

2.记录当前节点的叶子节点数为k,若是'y',ans不变,若是'n',ans加上k/2 (看图即可理解)

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e2+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-8;
typedef long long ll;
int n,m;

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    int k=pow(2,n);
    for(int i=0;i<m;++i){
        int zi=k;
        string s;
        cin>>s;
        int ans=1;
        for(int j=0;j<s.size();++j){
            if(s[j]=='n')ans+=zi/2;
            zi/=2;
        }
        cout<<ans<<'\n';
    }
    return 0;
}
View Code 1
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e2+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-8;
typedef long long ll;
int n,m;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    int k=pow(2,n);
    for(int i=0;i<m;++i){
        int a=1;
        string s;
        cin>>s;
        for(int j=0;j<s.size();++j){
            a*=2;
            if(s[j]=='n')a+=1;
        }
        cout<<a-k+1<<'\n';
    }
    return 0;
}
View Code 2

 

口罩发放

思路:模拟...

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e2+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-8;
typedef long long ll;
int D,P;
unordered_map<string,int>pre,st;
struct E{
    string na,id,t;
    int p;
    bool operator<(const E&e)const{
        if(t!=e.t)
            return t<e.t;
        return p<e.p;
    }
};
struct EE{
    string na,id;
};
vector<EE>ans1,ans2;
bool check(string s){
    for(int i=0;i<s.size();++i){
        if(s[i]<'0'||s[i]>'9')return false;
    }
    return true;
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>D>>P;
    for(int i=1,T,S;i<=D;++i){
        cin>>T>>S;
        vector<E>ve;
        for(int j=0;j<T;++j){
            string s1,s2,t;
            int op;
            cin>>s1>>s2>>op>>t;
            E a={s1,s2,t,j};
            if(s2.size()==18&&check(s2)){
                ve.push_back(a);
                if(op==1&&!st[s1]){
                    ans2.push_back({s1,s2});
                    st[s1]=1;
                }
            }
        }
        sort(ve.begin(),ve.end());
        for(int j=0;j<ve.size();++j){
            if(i>pre[ve[j].na]&&S){
                ans1.push_back({ve[j].na,ve[j].id});
                pre[ve[j].na]=i+P;S--;
            }
        }
    }
    for(auto t:ans1){
        cout<<t.na<<' '<<t.id<<'\n';
    }
    for(auto t:ans2){
        cout<<t.na<<' '<<t.id<<'\n';
    }
    return 0;
}
View Code

 

完全二叉树的层序遍历

思路:dfs根据后序遍历的顺序对应出层序的顺序

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>PLI;
const int N=1e5+5,M=1e6+5,Mod=1e6;
const int INF=0x3f3f3f3f3f3f3f3f;

const double eps=1e-8;

int n;
vector<int>post,a,b;
void dfs(int u){
    if(u*2<=n)dfs(u*2);
    if(u*2+1<=n)dfs(u*2+1);
    a.push_back(u);
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    post=vector<int>(n);
    b=vector<int>(n+1);
    for(int i=0;i<n;++i)cin>>post[i];
    dfs(1);
    for(int i=0;i<n;++i){
        b[a[i]]=post[i];
    }
    for(int i=1;i<=n;++i){
        cout<<b[i];
        if(i!=n)cout<<" ";
    }
    return 0;
}
View Code

 

那就别担心了

思路:dfs求所有点到终点的路径条数,若有节点已遍历但无路径数则NO

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>PLI;
const int N=5e2+5,M=1e6+5,Mod=1e6;
const int INF=0x3f3f3f3f;

const double eps=1e-8;

int n,m,path[N];
vector<int>ve[N];
bool vis[N];
int dfs(int x){
    vis[x]=true;
    if(path[x])return path[x];
    for(auto v:ve[x]){
        path[x]+=dfs(v);
    }
    return path[x];
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=0,a,b;i<m;++i){
        cin>>a>>b;
        ve[a].push_back(b);
    }
    int x,y;
    cin>>x>>y;
    path[y]=1;
    int cnt=dfs(x);
    bool ok=true;
    for(int i=1;i<=n;++i){
        if(vis[i]&&!path[i]){
            ok=false;break;
        }
    }
    cout<<cnt<<' ';
    if(ok)cout<<"Yes";
    else cout<<"No";
    return 0;
}
View Code

 

标签:typedef,const,int,cin,春季,训练赛,long,2023,tie
From: https://www.cnblogs.com/bible-/p/17330429.html

相关文章

  • 西南民族大学 春季 2023 训练赛 8
    L1-1嫑废话上代码Talkischeap.Showmethecode.L1-2猫是液体a,b,c=map(int,input().split(''))print(a*b*c)L1-3洛希极限#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){doublea,c;intb;cin>>......
  • 2023 4 18
    1#include<iostream>2usingnamespacestd;3intmain(){4intnum=0;5inti,j,k;6for(i=0;i<4;i++){7for(j=0;j<4;j++){8k=8-i-j;9if(k<=6){10num++;11cout<<"time"<<num<......
  • 2023联合省选题解
    2023联合省选题解火车站签到题。可以发现,一段被覆盖的区间上任意两点联通,因此用差分维护连续段即可。intmain(){n=read(),m=read(),x=read();for(inti=1;i<=m;i++){intl=read(),r=read();bl[l]=1;br[r]=1;c[l]++,c[r+1]--;......
  • 2023.4.17每日总结
    <!DOCTYPEhtml><html><head><metacharset="utf-8"/><title>首页</title><linkrel="stylesheet"href="css/page.css"/><scripttype="text/......
  • 2023-4-18查漏pair
    pair是将2个数据组合成一组数据,当需要这样的需求时就可以使用pair,如stl中的map就是将key和value放在一起来保存。另一个应用是,当一个函数需要返回2个数据的时候,可以选择pair。pair的实现是一个结构体,主要的两个成员变量是firstsecond因为是使用struct不是class,所以可以直接使......
  • 2023-4-18补缺map
    map是STL的一个关联容器,它提供一对一的hash。第一个可以称为关键字(key),每个关键字只能在map中出现一次;第二个可能称为该关键字的值(value);map以模板(泛型)方式实现,可以存储任意类型的数据,包括使用者自定义的数据类型。Map主要用于资料一对一映射(one-to-one)的情況,map內部的实......
  • 2023-4-18补缺for(auto i : v)遍历容器元素
    for(autoi:v)遍历容器元素1.auto2.auto&3.constauto&4.constautoC++11新增了一种循环:基于范围(range-based)的for循环。这简化了一种常见的循环任务:对数组(或容器类,如vector和array)的每个元素执行相同的操作,如下例所示:doubleprices[5]={4.99,10.99,6.87,6.47......
  • 2023.4.18-人月神话-4月份读后感1
    最近,我阅读了人月神话的一部分,有了一些感受。过去,我对于编程的乐趣不是很了解。编程为什么有趣?首先是一种创建事务的纯粹快乐,其次快乐来自于开发对其他人有用的东西,第三是整个过程体现出魔术般的力量,第四是学习的乐趣,最后乐趣还来自于工作在如此易于驾驭的介质上。编程非常有趣,在......
  • 2023 ASP.NET Core 开发者路线图
    链接ASP.NETCoreDeveloperRoadmap......
  • 【愚公系列】2023年04月 .NET CORE工具案例-DeveloperSharp的使用(数据库)
    (文章目录)前言DeveloperSharp是一个研发中大型项目必备的系统平台。也是一个低代码平台。它主要包括了如下一些功能:基于Sql语句、存储过程、事务、分页的数据库操作。并几乎支持市面上所有种类的数据库。图片操作。裁剪、缩放、加水印。http请求调用(Post与Get)高效分页We......