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

西南民族大学 春季 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 main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cout<<"Talk is cheap. Show me the code.";
    return 0;
}
View Code

猫是液体

cout<<a*b*c;
View Code

洛希极限

#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 main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    double a,c;
    int b;
    cin>>a>>b>>c;
    double t=a;
    if(b==0)t*=2.455;
    else t*=1.26;
    cout<<fixed<<setprecision(2)<<t<<' ';
    if(c<t)cout<<"T_T";
    else cout<<"^_^";
    return 0;
}
View Code

调和平均

#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 main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    double x,s=0;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>x;
        x=1/x;
        s+=x;
    }
    s/=n;
    s=1/s;
    cout<<fixed<<setprecision(2)<<s;
    return 0;
}
View Code

胎压监测

#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 a[4],b,d,ma,p;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    for(int i=0;i<4;++i){
        cin>>a[i];
        if(a[i]>ma){
            ma=a[i];p=i;
        }
    }
    cin>>b>>d;
    int s=0,t;
    for(int i=0;i<4;++i){
        if((i!=p&&abs(a[i]-ma)>d)||a[i]<b){
            s++;
            if(s==1)t=i;
        }
    }
    if(s==0)cout<<"Normal";
    else if(s==1)cout<<"Warning: please check #"<<t+1<<"!";
    else cout<<"Warning: please check all the tires!";
    return 0;
}
View Code

 

吃火锅

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

#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

 刮刮彩票

#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 a[4][4];
unordered_map<int,int>mp;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int s=45,xx,yy;
    for(int i=1;i<=3;++i)
        for(int j=1;j<=3;++j){
            cin>>a[i][j];
            s-=a[i][j];
            if(a[i][j]==0)xx=i,yy=j;
        }
    a[xx][yy]=s;
    for(int i=0,x,y;i<3;++i){
        cin>>x>>y;
        cout<<a[x][y]<<'\n';
    }
    int k;
    cin>>k;
    mp[6]=10000,mp[7]=36,mp[8]=720,mp[9]=360,mp[10]=80,mp[11]=252,mp[12]=108;
    mp[13]=72,mp[14]=54,mp[15]=180,mp[16]=72,mp[17]=180,mp[18]=119,mp[19]=36;
    mp[20]=306,mp[21]=1080,mp[22]=144,mp[23]=1800,mp[24]=3600;
    s=0;
    if(k<=3){
        for(int i=1;i<=3;++i){
            s+=a[k][i];
        }
    }
    else if(k<=6){
        k-=3;
        for(int i=1;i<=3;++i){
            s+=a[i][k];
        }
    }
    else if(k==7){
        for(int i=1;i<=3;++i)s+=a[i][i];
    }
    else{
        for(int i=1;i<=3;++i){
            s+=a[i][3-i+1];
        }
    }
    cout<<mp[s];
    return 0;
}
View Code

 

简单计算器

#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;
stack<int>s1;
stack<char>s2;
int n;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=0,x;i<n;++i){
        cin>>x;
        s1.push(x);
    }
    for(int i=1;i<n;++i){
        char x;
        cin>>x;
        s2.push(x);
    }
    int ans;
    bool ok=false;
    while(s1.size()>1&&!s2.empty()){
        int n1=s1.top();s1.pop();
        int n2=s1.top();s1.pop();
        char op=s2.top();s2.pop();
        if(op=='+'){
            ans=n1+n2;
            s1.push(n1+n2);
        }
        else if(op=='-'){
            ans=n2-n1;
            s1.push(n2-n1);
        }
        else if(op=='*'){
            ans=n2*n1;
            s1.push(n2*n1);
        }
        else{
            if(n1==0){
                cout<<"ERROR: "<<n2<<"/"<<n1;
                ok=true;break;
            }
            s1.push(n2/n1);
            ans=n2/n1;
        }
    }
    if(!ok)cout<<ans;
    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

 

网红点打卡攻略

#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 a[N][N];

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;

    for(int i=0,u,v,c;i<m;++i){
        cin>>u>>v>>c;
        a[u][v]=a[v][u]=c;
    }
    int k,ans=INF,id,all=0;
    cin>>k;
    for(int i=1,x,pre,s;i<=k;++i){
        cin>>x;
        s=0,pre=0;
        unordered_set<int>se;
        bool ok=true;
        for(int j=0,y;j<x;++j){
            cin>>y;
            if(se.count(y)==1)ok=false;
            se.insert(y);
            if(a[pre][y])s+=a[pre][y];
            else ok=false;
            pre=y;
        }
        if(!a[pre][0])ok=false;
        else s+=a[pre][0];
        if(se.size()==n){
            if(ok){
                all++;
                if(ans>s)ans=s,id=i;
            }
        }
    }
    cout<<all<<'\n';
    cout<<id<<' '<<ans;
    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

 

posted @ 2023-04-18 22:02  bible_w  阅读(11)  评论(0编辑  收藏  举报