第五届辽宁省大学生程序设计竞赛 (大连)

第五届辽宁省大学生程序设计竞赛(大连)

2024.11.5 13:00————16:00

过题数4/13
补题数7/13

  • 爱上字典
  • 比分幻术
  • 插排串联
  • 都市叠高
  • 俄式简餐
  • 飞沙走蛇
  • 顾影自怜
  • 划分数字
  • 野兽节拍
  • 结课风云
  • 可重集合
  • 龙之研习
  • 盲盒谜题

[A - 爱上字典]

在这里插入图片描述
题解:
将所有字母变成小写,方便map查询。当找到特殊字符或空格时,标记这个单词出现过,将所有已经认识的单词的状态改变,最后输出需要查询的单词数量。
代码:

#include <iostream>
#include <set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<string.h>
#include<map>
#include<math.h>

using namespace std;
#define int long long
string s1;int n;
map<string,bool>mp;

void solve(){
    getline(cin,s1);
  //  cout << s1 << endl;
  string s;
  for (int i = 0; i < s1.length(); i++) {
      if('A' <= s1[i] && s1[i] <= 'Z') {
          s1[i] += 32;
      }
      if(s1[i] == '!' || s1[i] == '?' || s1[i] == '.' || s1[i] == ',' ) {
          mp[s] = true;
          s.clear();
          i++;
      }
      else if(s1[i] == ' ') {
          mp[s] = true;
          s.clear();
      }
      else s = s+s1[i];
  }
    cin >> n;
  for (int i = 0; i < n; i++) {
      string s2;
      cin >> s2;
      for (int j = 0; j < s2.length(); j++) {
          if ('A' <= s2[j] && s2[j] <= 'Z') {
              s2[j] += 32;
          }
      }
      mp[s2] = false;
   //   cout << s2 <<  endl;
  }int ans = 0;
  for (auto x : mp) {
   //   cout << x.first << ' '<< x.second << endl;
      if(x.second == 1) ans++;
 //     cout << x.first << ' ' << ans << endl;
  }cout << ans << endl;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T = 1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

[B - 比分幻术]

在这里插入图片描述
题解:
//
代码:

#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve(){
    string s;
    cin >> s;
    cout << s[2] << s[1] << s[0] ;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T = 1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

[C - 插排串联]

在这里插入图片描述

题解:
从叶子节点往上找,记录每个插座所需要的大小,接着从小到大查找插座是否能满足条件。
1.插座限制功率为2200
2.查找插座大小时不要加上自己,自己是电器不是插座
代码:

#include <set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<string.h>
#include<map>
#include<math.h>

using namespace std;
#define int unsigned long long
int n;
int vis[100005];
int fa[100005];
int a[100005];
int la[100005];
vector<int>p;
vector<int>q;

void solve(){
    cin >> n;
    int res = 0;
    for (int i = 1; i <= n; i++) {
        cin >> fa[i];
        cin >> a[i];
        vis[fa[i]] = 1;
    }
    for (int i = 1; i <= n; i++) {
        if(vis[i] == 0) {
            res += a[i];
            int x = i;
            while(fa[x] != 0) {
                la[fa[x]] += a[i];
                x = fa[x];
            }
        }else q.push_back(a[i]);
    }
    if(res > 2200) {
        cout << "NO" << endl;
        return ;
    }sort(q.begin(),q.end());
 //   for (auto m : q) cout << m << ' ';cout << endl;
    for (int i = 1; i <= n; i++) {
        if(la[i] != 0) {
            p.push_back(la[i]);
        }
    }sort(p.begin(),p.end());
    int j = 0;
    for (auto x : p) {
        if(j >= q.size()) {
            cout << "NO" ;
            return ;
        }
     //   cout << x << ' ' << q[j] << endl;
        if(q[j] >= x) j++;
        else {
            while(q[j] < x && j < q.size()) {
                j++;
            }
            if(j >= q.size()) {
                cout << "NO" ;
                return ;
            }
            if(q[j] >= x) j++;
        }
    }cout << "YES";
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T = 1;
  //  cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

[D - 都市叠高]

在这里插入图片描述

题解:
给出一串点,进行分割线段,要求最远点的距离之和最大。dp思想,思考每个点出现后的最大值,对于前面的点来说应该在哪个点分割可以最大。
代码:

#include <iostream>
#include <set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<string.h>
#include<map>
#include<math.h>

using namespace std;
#define int long long
#define double long double
#define PII pair<double,double>
vector<PII>v;
int n;
const int N =5100;
double dp[N];

double dis(PII u,PII m) {
    return sqrt((u.first-m.first)*(u.first-m.first)+(u.second-m.second)*(u.second-m.second));
}

void solve(){
    cin >> n;
    for (int i = 1; i <= n; i++) {
        double x,y;cin >> x >> y;
        v.push_back({x,y});
    }
    dp[0] =0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            dp[i] = max(dp[j-1]+dis(v[i-1],v[j-1]),dp[i]);
       //     cout << dis(v[i-1],v[j-1]) << endl;
       //     cout << i << ' ' << dp[i] << endl;
        }
    }
    printf("%0.8Lf\n",dp[n]);
 //   cout << dp[n] << endl;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
 //   cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

[E - 俄式简餐]

在这里插入图片描述

题解:
可以考虑,所能组成的方块的最小单位是14,26。思考这俩种单元所能组成的所有情况,注意横着放与竖着放的区别。
可以先码住最小单元,然后任意组合即可。
代码:

#include <iostream>
#include <set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<string.h>
#include<map>
#include<math.h>

using namespace std;
#define int long long
int n,m;
int a[3][8];
int b[8][3];

void solve(){
    cin >> n >> m;
    if(n == 2 && m == 2) {
        cout << "NO" << endl;
        return ;
    }
    if(n % 4 == 0) {
        cout << "YES" << endl;int k = 1;
        for (int i = 1; i <= n/4; i++) {
            for (int j = 1 ; j <= 4; j++) {
                for (int p = k; p <= k+m-1; p++) {
                    cout << p << ' ';
                }cout << endl;
            }k+=m;
        }
    }
    else if(m % 4 == 0) {
        cout << "YES" << endl;
        int k = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = k; j <= k+m/4-1;j++) {
                for (int p = 1; p <= 4; p++) {
                    cout << j << ' ';
                }
            }cout << endl;k+=(m/4);
        }
    }
    else if(n % 2 == 0 && m % 2 == 0) {
        cout << "YES" << endl;
    //    cout << n << ' ' << m << endl;
        if(m ==2) {
            for (int i = 1; i <= 6; i++) {
                for (int j = 1; j <= 2; j++) cout << b[i][j] << ' ';
                cout << endl;
            }int k = 4;
            for (int i = 1; i <= (n-6)/4; i++) {
                for (int j = 1; j <= 4; j++) {
                    for (int p = 1; p <= 2; p++) {
                        cout << k+p-1 << ' ';
                    }cout << endl;
                }k+=2;
            }
        }
        else {
            for (int z = 1; z <= n / 2; z++) {
//            cout << n << ' ' << m << endl;
//            for (int i = 1; i <= 2; i++) {
//                for (int j = 1; j <= 6; j++) {
//                    cout << a[i][j] << ' ';
//                }
//            }
                int k = 4;
                for (int i = 1; i <= 2; i++) {
                    for (int j = 1; j <= 6; j++) {
                        cout << a[i][j] + (z - 1) * m / 2 << ' ';
                    }
                    for (int j = 1; j <= (m - 6) / 4; j++) {
                        for (int p = 1; p <= 4; p++) cout << k + (z - 1) * m / 2 << ' ';
                        k++;
                    }
                    cout << endl;
                }
            }
        }
    }else cout << "NO" << endl;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    cin>>t;
    a[1][1] = 1;a[2][1] = 1;a[2][2] = 1;a[2][3] = 1;
    a[1][6] = 2;a[2][4] = 2;a[2][5] = 2;a[2][6] = 2;
    a[1][2] = 3;a[1][3] = 3;a[1][4] = 3;a[1][5] = 3;
    b[1][1] = 1;b[1][2] = 1;b[2][1] = 1;b[3][1] = 1;
    b[2][2] = 2;b[3][2] = 2;b[4][2] = 2;b[5][2] = 2;
    b[4][1] = 3;b[5][1] = 3;b[6][1] = 3;b[6][2] = 3;
    while(t--){
        solve();
    }
    return 0;
}

[L - 龙之研习]

在这里插入图片描述

题解:
二分,先加上2024年以前的平年,1533层,然后计算k层龙之研习的时间,对于ans进行二分,对于p从0到8枚举,减去这些年里的闰年,就是平年。
代码:

#include<iostream>
#include <set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<string.h>
#include<map>
#include<math.h>

using namespace std;
#define int long long
int k;

bool check(int x) {
    int res = 0;
    int ls1 = 1,ls2 = 100;
    for (int i = 0; i <= 8; i++) {
        res += (x)/(4*ls1);
        res -= (x)/ls2;
        ls1*=100;ls2*=100;
    }
 //   cout << x << ' ' << res << ' ' << x-res << endl;
    return x-res >= k;
}

void solve(){
    cin >> k;
    k += 1533;
    int l = 2000,r = 2e18;
    while(l < r) {
        int mid = (l+r)/2;
        if(check(mid)) r = mid;
        else l = mid+1;
    }cout << r << endl;
    return ;
}

signed main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1; cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


[D - 都市叠高]

题解:
代码:


### 关于第五届辽宁省大学生程序设计竞赛大连“爱上字典”题目解析 目前提供的引用材料并未直接提及第五届辽宁省大学生程序设计竞赛的相关内容,尤其是“爱上字典”这一具体题目的详细信息。然而,可以基于已有的类似问题和常见字符串处理技巧进行推测并提供可能的解决方案。 #### 可能涉及的核心知识点 1. **字典序比较** 字典序是一种常见的字符串比较方式,在许多编程比赛中频繁出现。对于两个字符串 \( A \) 和 \( B \),如果存在某个位置使得该位置上的字符不同,则较小的那个字符所在的字符串具有更小的字典序[^2]。 2. **后缀数组与高度数组的应用** 后缀数组能够高效地解决与子串相关的查询问题。通过构建后缀数组及其对应的高度数组(LCP),可以在较短时间内完成对特定范围内的最小/最大字典序子串的查找操作[^1]。 3. **二分查找优化** 当面对大量询问时,利用二分法配合预处理后的数据结构可显著提升效率。例如,在寻找满足条件的第一个或最后一个元素场景下尤为适用。 4. **动态规划辅助求解最短路径等问题** 如果涉及到复杂状态转移关系或者需要记录额外信息(如结束字符), 动态规划可能是必要的工具之一. 以下是针对假设条件下的一种实现方法: ```python def preprocess(s): n = len(s) sa = sorted(range(n), key=lambda i: (s[i:], i)) rank = [0]*n for i in range(n): rank[sa[i]] = i height = [] k=0 for i in range(n): if rank[i]==0: continue j=sa[rank[i]-1] while(i+k<n and j+k<n and s[i+k]==s[j+k]): k+=1 height.append(k) if k>0:k-=1 return sa,height def solve_query(l,r,s,sa,height): idx_l,idx_r=l-1,r pos_left=bisect.bisect_right(sa,idx_l)-1 pos_right=bisect.bisect_left(sa,idx_r) min_suffix=min(pos_left+1,pos_right) length=len(s)-sa[min_suffix] end_char=s[-1] # Binary search to find minimal larger suffix within bounds. low,high=pos_left+1,pos_right-1 res=None while(low<=high): mid=(low+high)//2 current_suffix_start=sa[mid] cmp_result=-1 if s[current_suffix_start:]<s[l:r+1] else (+1 if s[current_suffix_start:]>s[l:r+1] else 0 ) if(cmp_result==1 or high-low<=1): res=current_suffix_start break elif(cmp_result==-1): low=mid+1 else: high=mid-1 result_length=res-l+len(s)+1 if res is not None else -1 result_endchar=s[res+len(s)-(r-l)]if res is not None else '?' return (result_length,result_endchar) # Example Usage S="abcab" queries=[(1,3),(2,4)] SA,H=preprocess(S) results=[] for query in queries: results.append(solve_query(*query,S,SA,H)) print(results) ``` 上述代码展示了如何通过对输入字符串\( S \) 进行预处理得到其后缀数组以及相应的height数组,并据此快速响应多个区间查询请求的过程。 ####
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值