西南民族大学2023天梯选拔赛

发布时间 2023-03-28 00:59:24作者: Ke_scholar

L1-1 谢谢卡尔!

题目详情 - L1-1 谢谢卡尔! (pintia.cn)

注意输出 \ 需要 \\ ;

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e5+10;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    cout << "谢谢卡尔!\\(>_<)/" << endl;
    
    return 0;
}

L1-2 现在是,幻想时间!

题目详情 - L1-2 现在是,幻想时间! (pintia.cn)

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e5+10;
typedef long long ll;
int n,m,t;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    scanf("%d%d",&n,&t);
    printf("%.3f",(double)n * 1.0 / t);
    
    return 0;
}

L1-3 你是来陪可莉炸鱼的吗?

题目详情 - L1-3 你是来陪可莉炸鱼的吗? (pintia.cn)

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e5+10;
typedef long long ll;
int n,m,t,v[N],w[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    int ans  = 0;
    while(n--)
    {
        cin >> m;
        if(m < 100) 
        {
        ans ++;
        continue;    
        }
        else if(m < 200) 
        {
            ans += 2;
            continue;
        }
        else if(m < 300) 
        {ans += 5;
         continue;
        }
        else if(m < 400) 
        {
        ans += 10;
         continue;    
        }
        else 
        {
        ans += 15;
         continue;    
        }
    } 
    cout << ans << endl;
    
    return 0;
}

L1-4 扫雷游戏

题目详情 - L1-4 扫雷游戏 (pintia.cn)

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e5+10;
typedef long long ll;
int n,m,t,w[N];
char a[11][11], s[11][11];
int v[] = {-1,-1,-1,0,0,1,1,1},u[] = {-1,0,1,-1,1,-1,0,1};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i=0;i<n;i++ )
     for(int j = 0;j < m;j++)
      cin >> a[i][j]; 
    for(int i=0;i<n;i++)
     {
         for(int j=0;j<m;j++)
          {
         if(a[i][j] == '*')
          s[i][j] = '*';          
        else
        {
            int num = 0;
            for(int k = 0; k < 8; k ++)
            {
            int x = i + v[k], y = j + u[k];    
            if(x >= 0 && x < n && y>=0 && y<m && a[x][y] == '*')
                         num ++ ;
            }
            if(num == 0) s[i][j] = '.';
            else
            s[i][j] = num + '0';
          }    
          }
     }
     for(int i=0;i<n;i++)
     {
      for(int j=0;j<m;j++)
       cout    << s[i][j] ;
    cout << endl;
     }

    return 0;
    
}

L1-5 史莱姆

题目详情 - L1-5 史莱姆 (pintia.cn)

遍历字符串,每次循环将除当前字符以外的都标记为0, 下次循环到和前面一样的字符时因为上次标记了所以这次就直接跳过,不计数.

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e5+10;
typedef long long ll;
int n,m,t,w[N],ans;
char a[N], str[N];
int v[] = {-1,-1,-1,0,0,1,1,1},u[] = {-1,0,1,-1,1,-1,0,1};
bool vis[26];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    cin >> str;
    memset(vis, 0 ,sizeof(vis));
    for(int i=0;i<n;i++)
    {
        if(!vis[str[i] - 'a']) 
        {
            a[ans++] = str[i] ;    
            for(int j = 0; j < 26;j ++)
            {
                if(j == str[i] - 'a')
                 continue;
                vis[j] = 0; 
            }
            vis[str[i] - 'a'] = 1;
        }
    }
    cout << ans << endl;
    cout << a << endl;
    return 0;
}

L1-6 加密通信

题目详情 - L1-6 加密通信 (pintia.cn)

注意k可能大于n, 所以k要对n取余.

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e5+10;
typedef long long ll;
int n,m,t,w[N],ans,k;
char a[N], str[N];
bool vis[26];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> k; 
    cin >> str ;
    k %= n;
    for(int i = 0; i < 26; i++)
     cin >> w[i];
    for(int i = n - k; i < n ; i++ )
         a[m++] = str[i];
    for(int i = 0; i < n - k;i ++)
         a[m++] = str[i];
    for(int i = 0 ;i < m;i++)
        cout << w[a[i] - 'a']; 
    cout << endl;
    return 0;
}

L1-7 字符操作

题目详情 - L1-7 字符操作 (pintia.cn)

在循环里执行交换前后n字符串会超时, 所以用一个f来标记改字符串当前是否处于交换状态,处于交换状态则下次执行操作1就+n或者-n, 最后判断字符串是否还处于交换状态,是就先输出后n个字符,再输出前n个,否则直接输出.

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e6+10;
typedef long long ll;
int n,m,k;
string str;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> str >> k; 
    bool f = 0;
    while(k--)
    {
        int t,a,b;
        cin >> t >> a >> b;
        a-- ;
        b-- ;
        if(t == 1){
            if(f)
            {
                a += (a < n) ? n : (-n);
                b += (b < n) ? n : (-n);
            }
             swap(str[a], str[b]);            
        }

        else
          f = (f + 1) % 2;
    }
    if(f) cout << str.substr(n) << str.substr(0,n) << endl;
    else 
    cout << str << endl;
    return 0;
}

L1-8 vivo50!

题目详情 - L1-8 vivo50! (pintia.cn)

碰到挂科的直接跳过.

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e5+10;
typedef long long ll;
int n,m,k;
struct Info{
    string name;
    double five,jidian, all,de, zhi, deyu;
    int g;
    int pai;
}info[N];
bool cmp(Info a, Info b)
{
    if(a.all == b.all) return a.name < b.name;
    return a.all > b.all;

}
int main()
{
    int cnt=0;
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> k; 
    while(n--)
    {
        string s;
        double f, d, z, gg;
        cin >> s >> f >> d >> z >> gg;
        if(!gg) continue;
        info[cnt].name = s;
        info[cnt].de = min(100.0, 70.0 + d);
        info[cnt].jidian = f * 10.0 + 50.0;
        info[cnt].all = ((info[cnt].jidian + z) * 0.7 + info[cnt].de * 0.3);     
        cnt ++ ;        
    }
    sort(info, info + cnt, cmp);
    for(int i = 0; i < cnt; i++)
    {
        info[i].pai = i + 1;
        if(info[i].all == info[i-1].all) info[i].pai = info[i-1].pai;  
    }
    for(int i = 0; i < cnt ; i++)
    {
        if(info[i].pai > k) break;    
        printf("%d %s %.1lf\n",info[i].pai,info[i].name.c_str(),info[i].all);    
    }
    return 0;
}

L2-1 游戏圈

题目详情 - L2-1 游戏圈 (pintia.cn)

并查集模版题.

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e6+10;
typedef long long ll;
ll n,m,t,q,ans,f[N];
ll find(ll x)
{
    if(f[x] == x) return x;
    return f[x] = find(f[x]);
}
void add(ll x, ll y)
{
    if(find(x) != find(y))
      f[find(x)] = find(y);
}
int main()
{
    memset(f, 0, sizeof(f));
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1 ; i <= n; i++)
     f[i] = i;
     while(m--)
     {
         ll x, y;
         cin >> x >> y;
         add(x, y);
     }
     while(q--)
     {
       ll a,b;
       cin >> a >> b;
       if(find(a) != find(b))
        cout << "no" << endl;
       else 
        cout << "yes" << endl;    
     }
     for(ll i = 1; i <= n; i++)
      if(f[i] == i) ans++;
    cout << ans << endl;
    return 0;
}

L2-2 组套题

题目详情 - L2-2 组套题 (pintia.cn)

遇到题目要求的题数就用二维记录一下, 否则就放入队列, 然后判断>Ti难度的题与<Ti难度的题;

最后将二维转化成一维然后输出.

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e3 + 10;

typedef long long ll;
int n,m,a[N];
struct Juan{
    int tao, tinum;
};
bool cmp(Juan a, Juan b)
{
        if(b.tao == a.tao) return b.tinum > a.tinum;
        return b.tao > a.tao;    
}
vector<Juan> ans[N], cnt;
queue<Juan> q[N];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= 10; i++)
      cin >> a[i];     
    for(int i = 1; i <= n ; i ++) 
    {
        cin >> m;
        for(int j = 0; j < m ;j++)
        {
            string s;
            cin >> s;
            int x = 1;
            int a1,b1;
            a1 = b1 = 0;
            while(s[x] >= '0' && s[x] <= '9')
            {
            a1 = a1 * 10 + (s[x] - '0');
            x ++ ;    
            }
            x++;
            while(s[x] >= '0' && s[x] <= '9')
            {
            b1 = b1 * 10 + (s[x] - '0');
            x ++ ;    
            }
            if(a[a1]) 
            {
                a[a1] -- ;
                ans[a1].push_back({i, b1});
            }            
            else
               q[a1].push({i, b1});
        }
    }
    for(int i = 1 ;i <= 10; i++)
    {
        while(a[i])
        {
           bool f = 0;
           for(int j = i + 1; j <= 10; j++)
           {
           if(q[j].size())
             {
                 ans[j].push_back(q[j].front());
                 q[j].pop();
                 a[i] --;
                 f = 1;
                 break;
             }
           }
         if(f) continue;
         for(int j = i - 1; j >= 1; j--)
         {
             if(q[j].size())
             {
                 ans[j].push_back(q[j].front());
                 q[j].pop();
                 a[i] --;
                 f = 1;
                 break;
             }
         }
        }
     } 
     for(int i = 1; i <= 10; i++)
      if(ans[i].size())
      {
          sort(ans[i].begin(), ans[i].end(), cmp);
          for(Juan j : ans[i])
           cnt.push_back(j);
      }
    for(int i = 0 ;i < cnt.size() ; i++)
    {
        if(i) printf(" ");
        printf("%d-%d",cnt[i].tao, cnt[i].tinum);        
    }
    return 0;
}

L2-3 简单的数数

题目详情 - L2-3 简单的数数 (pintia.cn)

因为只判断10个数字以内的,所以可以将A数组中的每个数都和1到10的数进行合并,则当前数字的合并方案数就等于当前已有的方案数再加上和最后一个元素合并的上一个数字的方案数.

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1e5+10;
const int mod = 998244353;

typedef long long ll;
int dp[N][11],n,m,a,b,c;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    cin >> a;
    dp[1][a] = 1;
    for(int i = 2; i <= n ;i++) 
     {
         cin >> a;
         for(int j = 0 ;j < 10; j ++)
         {
             b = (a + j) % 10;
             c = (a * j) % 10;
             dp[i][b] = (dp[i][b] + dp[i-1][j]) % mod;
             dp[i][c] = (dp[i][c] + dp[i-1][j]) % mod;
         } 
     } 
    for(int i = 0; i < 10 ;i++)
     cout << dp[n][i] << endl;
    return 0;
}