第五届辽宁省大学生程序设计竞赛(大连)
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 - 都市叠高]
题解:
代码: