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

L1-1 自动编程

void solve()
{
    int x;
        cin >> x;
        cout << "print(" << x << ")"; 
}

L1-2 太神奇了

void solve()
{
    cin >> n >> m;
    cout << n + m - 1 << endl; 
}

L1-3 洛希极限

void solve()
{
    double p,q;
    cin >> p >> n >> q;
    if(n ==0)
    {
        double ans = p * 2.455;
        if(ans <= q)
         printf("%.2f ^_^",ans);
        else
         printf("%.2f T_T",ans);
    }
    else
    {
        double ans = p * 1.26;
        if(ans <= q)
         printf("%.2f ^_^", ans);
        else
         printf("%.2f T_T", ans);
    }
}

L1-4 吃鱼还是吃肉

void solve()
{
    cin >> n >> m >> t;
    if(n == 1)
    {
        if(m == 130)
        {
            cout << "wan mei! ";
            if(t == 27)
             cout << "wan mei!" << endl;
            else if(t > 27)
             cout << "shao chi rou!" << endl;
            else
             cout << "duo chi rou!" << endl;
        }
        else if(m > 130)
        {
            cout << "ni li hai! ";
            if(t == 27)
             cout << "wan mei!" << endl;
            else if(t > 27)
             cout << "shao chi rou!" << endl;
            else
             cout << "duo chi rou!" << endl;
        }
        else
        {
            cout << "duo chi yu! ";
            if(t == 27)
             cout << "wan mei!" << endl;
            else if(t > 27)
             cout << "shao chi rou!" << endl;
            else
             cout << "duo chi rou!" << endl;
        }
    }
    else
    {
        if(m == 129)
        {
            cout << "wan mei! ";
            if(t == 25)
             cout << "wan mei!" << endl;
            else if(t > 25)
             cout << "shao chi rou!" << endl;
            else
             cout << "duo chi rou!" << endl;
        }
        else if(m > 129)
        {
            cout << "ni li hai! ";
            if(t == 25)
             cout << "wan mei!" << endl;
            else if(t > 25)
             cout << "shao chi rou!" << endl;
            else
             cout << "duo chi rou!" << endl;
        }
        else
        {
            cout << "duo chi yu! ";
            if(t == 25)
             cout << "wan mei!" << endl;
            else if(t > 25)
             cout << "shao chi rou!" << endl;
            else
             cout << "duo chi rou!" << endl;
        }
    }
}

L1-5 不变初心数

int chuxin(int x)
{
    int ans = 0;
    while(x)
    {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}
void solve()
{
    cin >> n; 
    t = chuxin(n * 2);
    bool f = 0;
    for(int i = 3; i < 10; i++)
    {
        if(chuxin(n * i) != t)
         f = 1;
    }
    if(f) cout << "NO" << endl;
    else cout << t << endl; 
}

L1-6 字母串

void solve()
{
    string str;
    cin >> str;
    bool f = true;
    t = 'a' - 'A';
    //cout << t << endl; 
    for(int i = 1; i < str.size(); i++)
    {
        //cout << f << ' ';
        if(str[i-1] >= 'A' && str[i-1]<='Z')
        { 
            if(abs(str[i] - str[i-1]) == 32)//'A' + 32
             continue;
            if(str[i] == str[i-1] + 1)//'A' + 1 
             continue;
        }
        else 
        {
            if(abs(str[i] - str[i -1]) == 32)//'a' - 32 
             continue;
            if(str[i] == str[i-1] - 1)//'a' - 1
            continue;
        }
             f = false;
             break;
    }
    cout << (f == false ? "N" : "Y") << endl;
}

L1-7 矩阵列平移

void solve()
{
    int k,x;
    cin >> n >> k >> x;
    for(int i = 0; i < n; i++)
     for(int j = 0; j < n; j++)
      cin >> g[i][j];

    for(int j = 0; j < n; j++)
    {    

        if(j & 1)
        {
            t++;
         if(t > k) t = 1;       
        for(int i = n - 1 - t; i >= 0; i--)
          g[i +t ][j] = g[i][j];
        for(int i = 0; i < t; i++)
         g[i][j] = x;            
        }
    }
    for(int i = 0; i < n; i++)
     for(int j = 0; j < n; j++)
       ans[i] += g[i][j];    
    for(int i = 0; i < n - 1; i++)
     cout << ans[i] <<' ';
    cout << ans[n-1] << endl;
      
} 

L1-8 均是素数

3for暴搜

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <utility>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
#define f first
#define s second

using namespace std;

const int N = 1e5+10, M = 1e6 + 10;

//typedef long long ll;
typedef pair<int,int> PII;
queue<PII> q1;
priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,ans;
//bool vis[N] = false;
bool ss(int x)
{
    if(x < 2) return false;
    if(x == 2) return true;
    for(int i = 2; i <= sqrt(x); i++)
     if(x % i == 0) return false;
    return true;
}
void solve()
{
     cin >> n >> m;
     for(int i = n; i < m - 1; i++)
     {
         if(!ss(i)) continue;
         for(int j = i + 1; j < m; j++)
         {
             if(!ss(j)) continue;
             for(int k = j + 1; k <= m; k ++)
             {
              if(!ss(k)) continue;
               if(ss(i * j + k) && ss(i * k + j) && ss(j * k + i))
               {
                   //vis[i * j + k] = true;
                ans ++;                   
               }
             }

         }
     } 
     cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int Ke_scholar;
    Ke_scholar = 1;
    while(Ke_scholar--)
    {
       solve();
    }
    return 0;
}

L2-1 盲盒包装流水线

用map维护勋章放进对应的盒子里

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long

using namespace std;

const int N = 1e5+10, M = 1e7 + 10;

//typedef long long ll;
typedef pair<int,int> PII;
queue<PII> q1;
priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,s,ans[N];
set<int> f;
bool vis[N];
string str[N];
map<string, int> mapp;
/*

*/
void solve()
{
    cin >> n >> s;
    for(int i = 1; i <= n; i++)
     cin >> str[i];
    for(int i = 1;i <= n / s; i++)
     for(int j = 1;j <= s; j++)
      cin >> mapp[str[i * s - j + 1]];
    cin >> t;
    while(t--)
    {
        string s;
        cin >> s;
        if(mapp.count(s)) cout << mapp[s] << endl;
        else
         cout << "Wrong Number" << endl; 
    }
      
} 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int Ke_scholar ;
    Ke_scholar = 1;
    while(Ke_scholar--)
    {
       solve();
    }
    return 0;
}

L2-2 点赞狂魔

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <utility>
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
#define f first
#define s second

using namespace std;

const int N = 110, M = 1e7 + 10;

//typedef long long ll;
typedef pair<int,int> PII;
queue<PII> q1;
priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t = 0,ans[N];
struct Name{
    string name;
    int k,as;
    
}Zan[N];
int f[M];
bool vis[N];
int g[N][N];
/*

*/
bool cmp(Name a, Name b)
{
    if(a.as == b.as) return a.k <b.k;
    return a.as > b.as; 
}
void solve()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        memset(vis, 0, sizeof(vis));
     cin >> Zan[i].name >> Zan[i].k;
      for(int j = 0; j < Zan[i].k;j ++)
      {
       cin >> f[j];    
       if(!vis[f[j]]) 
       {
           vis[f[j]] = 1;
           Zan[i].as++;
       }          
      }
    } 
    sort(Zan, Zan + n, cmp);
    if(n < 3)
    {
        for(int i = 0; i < n; i++)
         cout << Zan[i].name << ' ';
        for(int i = n; i < 3; i++)
         cout << "-" << (i == 2 ? "\n" : " ");
    }
    else
     for(int i = 0; i < 3; i++) 
      cout << Zan[i].name << (i == 2 ? "\n" : " ");
      
} 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int Ke_scholar ;
    Ke_scholar = 1;
    while(Ke_scholar--)
    {
       solve();
    }
    return 0;
}

L2-3 浪漫侧影

参考题解:520 钻石争霸赛 2021 7-8 浪漫侧影 (25 分) - 代码先锋网 (codeleading.com)

左侧侧影其实是二叉树每层的第一个,右侧侧影是二叉树每层的最后一个,那我们在恢复树的过程中,先恢复左树,再恢复右树,最后根据层数存根节点,然后我们输出每层的第一个和最后一个即可.

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <utility>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long

using namespace std;

const int N = 1e5 + 10;
//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
bool vis[N];
int mid[N], hou[N];
vector<int> v[N];
/*
*/
int maxdeep;
void bulid(int root,int l1, int r2, int deep){
    if(l1 > r2) return ;
    int  cnt = l1;
    while(cnt <= r2 &&  mid[cnt] != hou[root])
        cnt ++;
    v[deep].push_back(hou[root]);
    maxdeep = max(maxdeep, deep);
    bulid(root - r2 + cnt - 1, l1, cnt - 1, deep + 1);
    bulid(root - 1, cnt + 1, r2, deep + 1);
}
void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> mid[i];
    for(int i = 1; i <= n; i++)
        cin >> hou[i];
    bulid(n, 1, n, 1);
    cout << "R:";
    for(int i = 1; i <= maxdeep; i++){
        cout << ' ' << v[i].back() ;
    }
    cout << endl;
    cout << "L:";
    for(int i = 1; i <= maxdeep; i ++){
        cout << ' ' << v[i].front() ;
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int Ke_scholar  = 1;
    while(Ke_scholar--)
        solve();
    return 0;
}

 

 

L2-4 哲哲打游戏

用nowl记录当前位置,一个cun数组记录存档,用一个二维动态数组记录每个点能到达的剧情点,然后跟着模拟即可,0的时候nowl等于对应的剧情点,1的时候记录存档点并输出当前nowl位置,2的时候读一下档,nowl变成对应档位的位置.

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <set>
#include <utility>
#define inf 0x3f3f3f3f
#define endl '\n'
//#define int long long
#define f first
//#define s second

using namespace std;

const int N = 1e5+10, M = 1e6 + 10;

//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,pat[N];
/*
*/
double p[N];
vector<PII> a;
vector<vector<int>> v(N);
void solve()
{
    cin >> n >> m;
    v[0].push_back(0);
    for(int i = 1; i <= n ;i ++)
    {
        int k;
        cin >> k;
        for(int j = 1; j <= k; j++){
            int x;
            cin >> x;
            v[i].push_back(x);
        }
    }
    int cun[N];
    int nowl = 1;
    while(m--){
        int x, y;
        cin >> x >> y;
        if(x == 0){
            y--;
            nowl = v[nowl][y];
            //cout << nowl << endl;
        }
        else if(x == 1){
            cun[y] = nowl;
            cout << nowl << endl;
        }
        else{
            nowl = cun[y];
        }
    }
    cout << nowl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int Ke_scholar  = 1;
    while(Ke_scholar--)
    {
        solve();
    }
    return 0;
}

L3-2 拼题A打卡奖励

正着求最大花费会因为背包容量而超时只能拿19分.

原题解:L3-2 拼题A打卡奖励 (30 分)_NEFU AB-IN的博客-CSDN博客

可以发现背包的容量很大,但是获利比较少,所以可以采用01背包的逆过程

可以把获利看作背包容量,把原来的背包容量当作获利
也就是我们要求,在当前获利下,最少需要的背包容量是多少?
最后按照获利的总数逆序遍历,找到第一个体积容量小于等于背包容量的获利,就是答案

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <utility>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long

using namespace std;

const int N = 1e5 + 10;
//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
bool vis[N];
int mid[N], hou[N];
vector<int> v[N];
/*
*/
int num[N],c[N],dp[364 * 24 *60];
void solve()
{
    memset(dp, inf, sizeof dp);
    dp[0] = 0;
    cin >> n >> m;
    int sum = 0;
    for(int i = 1; i <= n; i++) {
        cin >> num[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> c[i];
        sum += c[i];
    }
    for(int i = 1;i <= n; i++){
        for(int j = sum;j >= c[i]; --j){
                dp[j] = min(dp[j], dp[j - c[i]] + num[i]);
        }
    }
    for(int i = sum; i >= 0; i--){
        if(dp[i] <= m){
            cout << i;
            return ;
        }
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int Ke_scholar  = 1;
    while(Ke_scholar--)
        solve();
    return 0;
}

 

posted @ 2023-04-11 23:13  Ke_scholar  阅读(27)  评论(0编辑  收藏  举报