本文主要是介绍石家庄学院2024年大学生程序设计大赛题解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
石家庄学院2024年大学生程序设计大赛题解
A 杨辉三角
类型:模拟
注意:行末空格问题(WA了一次)
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cn#include <bits/stdc++.h>using namespace std;long long sanjiao[35][35];void init() {sanjiao[1][1] = 1;for (int i = 2; i <= 30; i++) {for (int j = 1; j <= i; j++) {sanjiao[i][j] = sanjiao[i - 1][j] + sanjiao[i - 1][j - 1];}}
}void slove(int n) {for (int i = 1; i <= n; i++) {for (int j = 1; j <= i; j++) {if (j == 1) cout << sanjiao[i][j];else cout << " " << sanjiao[i][j];}cout << endl;}
}int main() {init();int n;while (scanf("%d", &n) != EOF) {slove(n);cout << endl;}
}
B 金牌厨师
类型:差分
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cn#include <bits/stdc++.h>
using namespace std;
const int N = 300050;
int a[N];int main() {int n, m;cin >> n >> m;for(int i = 0; i < m; i ++) {int x, y;cin >> x >> y;a[x] ++ , a[y + 1] --;}for(int i = 1; i <= n; i ++) {a[i] = a[i] + a[i - 1];}int ans = -1;for(int i = 0; i <= n; i ++) {ans = max(ans, min(a[i], n - i));}cout << ans;
}
C 峻峻的信仰
类型:模拟
以为会 TLE 需要优化,但是数据并不大,侥幸 AC。(题目没有给 M 的范围)
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cn#include <bits/stdc++.h>using namespace std;int f(int n) {int sum = 0;for (int i = 1; i <= n / 2; i++) {if (n % i == 0) sum += i;}return sum;
}int main() {int m;cin >> m;for (int i = 0; i < m; i++) {int x, y;cin >> x >> y;if (f(x) == y && f(y) == x) cout << "YES";else cout << "NO";cout << endl;}
}
D 斗地主之扑克比大小
类型:大模拟
字多不要慌,慢慢分析,将不同情况分类。
扑克点数大小比较使用了列表的 indexOf
方法(返回指定元素在列表中的索引),比较索引大小。所以用了Java实现。
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cnimport java.util.*;public class Main {static final List<String> p = Arrays.asList("3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER");public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {String s = sc.nextLine();String[] ss = s.split("-");String s1 = ss[0], s2 = ss[1];// 6: joker// 5: ShunZiint s1_type;String s1_val = null;String[] s1_split = s1.split(" ");int s1_length = s1_split.length;if (s1_length == 1) {s1_type = 1;s1_val = s1_split[0];} else if (s1_length == 2) {// jokerif (s1_split[0].equals("joker") || s1_split[1].equals("joker")) {s1_type = 6;} else {// 2s1_type = 2;s1_val = s1_split[0];}} else if (s1_length == 3) {s1_type = 3;s1_val = s1_split[0];} else if (s1_length == 4) {s1_type = 4;s1_val = s1_split[0];} else {s1_type = 5;s1_val = s1_split[0];}int s2_type;String s2_val = null;String[] s2_split = s2.split(" ");int s2_length = s2_split.length;if (s2_length == 1) {s2_type = 1;s2_val = s2_split[0];} else if (s2_length == 2) {// jokerif (s2_split[0].equals("joker") || s2_split[1].equals("joker")) {s2_type = 6;} else {// 2s2_type = 2;s2_val = s2_split[0];}} else if (s2_length == 3) {s2_type = 3;s2_val = s2_split[0];} else if (s2_length == 4) {s2_type = 4;s2_val = s2_split[0];} else {s2_type = 5;s2_val = s2_split[0];}if (s1_type == 6) {System.out.println(s1);continue;}if (s2_type == 6) {System.out.println(s2);continue;}if (s1_type == s2_type) {if (p.indexOf(s1_val) > p.indexOf(s2_val)) {System.out.println(s1);} else {System.out.println(s2);}continue;}if (s1_type == 4) {System.out.println(s1_val);continue;}if (s2_type == 4) {System.out.println(s2_val);continue;}System.out.println("ERROR");}}
}
E 天干地支
类型:模拟
题目中说"没有余数就是天干的最后一个" → 将最后一个放在余数 0 的位置
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cn#include <bits/stdc++.h>using namespace std;string tiangan[14] = {"癸", "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
string dizhi[14] = {"亥", "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};int main() {int n;cin >> n;n -= 3;cout << tiangan[n % 10] << dizhi[n % 12] << endl;
}
F 密室逃脱
类型:模拟
注:没看到 “每串数字第一个数是n” 😤 ,WA好多次。cpp应该更好实现 🤔。
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cnimport java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (true) {long ans = 0;String s = sc.nextLine();if ("0".equals(s)) break;String[] s1 = s.split(" ");for (int i = 1; i < s1.length; i++) {long num = Long.parseLong(s1[i]);if(num == 0) break;if(num % 2 == 0) ans += num;}System.out.println(ans);}}
}
G 振兴中华
类型:动态规划 / 深搜
仔细观察数据,发现数据非常规律。走的当前的格子必然是从上方或者左边的格子走过来的。
队友说数数就行 🤣
# team: TianShengYiDui-SJZC
# wmh: wmhwiki.cn
# yx: forxuan.cn
# sgx: gxwiki.cn
print(35)
我的想法是深搜
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cn#include <iostream>
#include <vector>
#include <string>
using namespace std;int count = 0;vector<string> grid = {"01234","12345","23456","34567"
};
string target = "01234567";void dfs(int x, int y, int index) {if (x < 0 || x >= grid.size() || y < 0 || y >= grid[0].size() || grid[x][y] != target[index]) {return;}if (index == target.size() - 1) {if (grid[x][y] == target[index])count++;return;}dfs(x + 1, y, index + 1);dfs(x - 1, y, index + 1);dfs(x, y + 1, index + 1);dfs(x, y - 1, index + 1);
}int main() {dfs(0, 0, 0);cout << count << endl;// 35return 0;
}
H Tuhao’s Task
类型:贪心
按照结束时间排序,从第一个开始枚举,则下一个合法的任务的必然结束时间最早。
英文题,大神队友一发AC。膜拜大佬🤩
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cn#include <bits/stdc++.h>using namespace std;
typedef struct Node {int a, b, c, d;
} Node;bool cmp(Node x, Node y) {if (x.c != y.c) return x.c < y.c;if (x.d != y.d) return x.d < y.d;
}int main() {int m;while (1) {cin >> m;if (m == 0) return 0;vector <Node> v;for (int i = 0; i < m; i++) {int a, b, c, d;cin >> a >> b >> c >> d;v.push_back({a, b, c, d});}int ans = 0;sort(v.begin(), v.end(), cmp);int ec = v[0].c, ed = v[0].d;for (int i = 1; i < v.size(); i++) {int sc = v[i].a;int sd = v[i].b;if (sc > ec || (sc >= ec && sd >= ed)) {ans++;ec = v[i].c;ed = v[i].d;}}ans++;cout << ans << endl;}
}
I Nim Game
😭 俺不会
J 难题
类型:数论
参考:正方形分割问题:把一个给定的正方形分割成n个互不重叠的小正方形,这里哪些n可以,哪些n不可以,为什么? - 知乎 (zhihu.com)
// team: TianShengYiDui-SJZC
// wmh: wmhwiki.cn
// yx: forxuan.cn
// sgx: gxwiki.cn#include <bits/stdc++.h>using namespace std;int main() {long long n;cin >> n;if (n == 2 || n == 3 || n == 5) cout << "NO";else cout << "YES";
}
这篇关于石家庄学院2024年大学生程序设计大赛题解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!