上海市计算机学会竞赛平台 | 2022 二星级挑战

  • 康托表
  • 打印K型
  • 计算天数(Python)
  • 黑色星期五
  • 分割队伍
  • 调配问题(一)
  • 阶乘的余数
  • 驼峰与蛇
  • 四方定理
  • 数根
  • IP地址
  • 最年长的人
  • 选科组合
  • 合成游戏
  • 循环节的判定
  • 中心对称数
  • 扫雷
  • 永恒的生命游戏
  • 计算GPA
  • 九宫格键盘
  • 闯关升级
  • 三倍游戏
  • 救援争先
  • 数字验证
  • 评测队列
  • 买二送一
  • 考试排名
  • 巧妙的数
  • 三倍子串
  • 没有考试的天数

此文章仅供学习交流,不得抄袭刷分!!!

康托表

#include<iostream>
using namespace std;
int a, b;
int main() {cin >> a >> b;cout << (1 + a + b - 1 - 1)*(a + b - 1 - 1) / 2 + ((a + b) % 2 ? a : b);return 0;
}

打印K型

#include<iostream>
using namespace std;
int n;
int main() {cin.tie(0);cout.tie(0);cin >> n;for (int i = 0; i < n; ++i) {cout << "**";for (int j = 0; j < n - i; ++j)cout << " ";for (int j = 0; j < n - i; ++j)cout << "*";cout << endl;}cout << "***" << endl;for (int i = n - i - 1; i >= 0; --i) {cout << "**";for (int j = 0; j < n - i; ++j)cout << " ";for (int j = 0; j < n - i; ++j)cout << "*";cout << endl;}return 0;
}

计算天数(Python)

sum = 0
year, month, day = input().split('-')
year = int(year)
month = int(month)
day = int(day)
dayNum = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]if year % 400 == 0 or year % 4 == 0 and year % 100 != 0:dayNum[3] += 1
for i in range(month):sum += int(dayNum[i])
print(sum + day)

黑色星期五

#include<iostream>
using namespace std;int days[13] = {0, 12, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};
int y, w, cnt;
int main() {cin >> y >> w;cnt = w;if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0)days[3]++;for (int i = 1; i <= 12; i++) {cnt = (cnt + days[i]) % 7;if (cnt == 5)cout << i << endl;}return 0;
}

分割队伍

#include <iostream>
#include <cmath>
#include <climits>
using namespace std;int n, a[100001], s[100001], sum, minn = INT_MAX;int main() {cin.tie(0);cin >> n;for (int i = 1; i <= n; i ++) {cin >> a[i];s[i] = s[i - 1] + a[i];sum += a[i];}for (int i = 1; i <= n - 1; i ++)minn = min(minn, abs(sum - s[i] - s[i]));cout << minn;return 0;
}

调配问题(一)

#include <cmath>
#include <iostream>
using namespace  std;
int n;
long long s = 0, ans = 0, a;
int main() {cin.tie(0);cin >> n;for (int i = 0; i < n; ++i) {cin >> a;s += a;ans += abs(s);}cout << ans;return 0;
}

阶乘的余数

#include <iostream>
using namespace std;
long long n, m, sum = 1;
int main() {cin.tie(0);cin >> n >> m;for (int i = 1; i <= n; i++) {sum *= i;sum %= m;}cout << sum % m;return 0;
}

驼峰与蛇

#include <iostream>
#include <cstring>
using namespace std;
char name[1000001];
int main() {int i, len;cin >> name;len = strlen(name);for (i = 0; i < len; ++i) {if (name[i + 1] >= 'A' && name[i + 1] <= 'Z' && (name[i] >= 'A' && name[i] <= 'Z')) {name[i] = tolower(name[i]);cout << name[i] << "_";} else if (name[i + 1] >= 'A' && name[i + 1] <= 'Z')cout << name[i] << "_";else if (name[i] >= 'A' && name[i] <= 'Z') {name[i] = tolower(name[i]);cout << name[i];} else {cout << name[i];}}return 0;
}

四方定理

#include <iostream>
#include <cmath>
using namespace std;
long long n, i, j, k, l;
int main() {cin.tie(0);cin >> n;double f = int(sqrt(n));for (i = 0; i <= f; ++i)for (j = i; j <= f; ++j)for (k = j; k <= f; ++k)for (l = k; l <= f; ++l)if ((i * i + j * j + k * k + l * l) == n)cout << i << " " << j << " " << k << " " << l << endl;return 0;
}

数根

#include <iostream>
using namespace std;
char c;
long long sum;
int main() {while (cin >> c)sum += c - '0';cout << (sum - 1) % 9 + 1;return 0;
}

IP地址

#include <iostream>
using namespace std;int main() {for (int i = 1; i <= 4; i ++) {char ch;int num = 0;for (int j = 1; j <= 8; j ++) {cin >> ch;num = num * 2 + ch - '0';}cout << num;if (i != 4) cout << '.';}return 0;
}

最年长的人

#include<cstdio>
#include<iostream>
using namespace std;struct data {int year;int month;int day;
};bool datass(data x, data y) {if (x.year == y.year) {if (x.month == y.month)return x.day < y.day;elsereturn x.month < y.month;} elsereturn x.year < y.year;
}int main() {int n;struct data a[1000000];cin >> n;for (int i = 0; i < n; i++)scanf("%d-%d-%d", &a[i].year, &a[i].month, &a[i].day);sort(a, a + n, datass);printf("%04d-%02d-%02d", a[0].year, a[0].month, a[0].day);return 0;
}

选科组合

#include <iostream>
using namespace std;
int a[6], maxx = 0, mid = 0, minn = 0;
int main() {for (int i = 0; i < 6; ++i) {cin >> a[i];if (a[i] > maxx) {minn = mid;mid = maxx;maxx = a[i];} else if (a[i] > mid) {minn = mid;mid = a[i];} else if (a[i] > minn)minn = a[i];}cout << maxx + mid + minn;return 0;
}

合成游戏

#include<iostream>
using namespace std;
long long n, m, ans = 0, power = 1;
int main() {cin.tie(0);cin >> n;for (int i = 0; i < n; i++) {cin >> m;ans += m;}while (power <= ans)power *= 2;cout << power / 2;return 0;
}

循环节的判定

#include<iostream>
using namespace std;
int main() {string s, a, c = "";cin >> s >> a;int len = s.length() / a.length();for (int i = 0; i < len; i++)c += a;if (s == c) {cout << "Yes";return 0;}cout << "No";return 0;
}

中心对称数

#include<bits/stdc++.h>
using namespace std;
string a;
char b[10];
int main()
{cin>>a;b[1]='1';b[8]='8';b[0]='0';b[6]='9';b[9]='6';int i,n=a.size();for(i=0;i<n;i++){if(a[i]=='2'||a[i]=='3'||a[i]=='4'||a[i]=='5'||a[i]=='7'){printf("Not a strobogrammatic number");return 0;}else if(!(a[i]==b[a[n-i-1]-'0'])){printf("Not a strobogrammatic number");return 0;}}printf("Strobogrammatic number");return 0;
}

扫雷

#include <iostream>
using namespace std;int n, m;
char a[105][105];int search(int x, int y) {int ans = 0;for (int i = x - 1; i <= x + 1; i++)for (int j = y - 1; j <= y + 1; j++)if (a[i][j] == '*')ans++;return ans;
}int main() {cin >> n >> m;for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)cin >> a[i][j];for (int i = 1; i <= n; i++) {for (int j = 1; j <= m; j++) {if (a[i][j] == '*')cout << '*';elsecout << search(i, j);}cout << endl;}return 0;
}

永恒的生命游戏

#include <iostream>
using namespace std;
int n, m;
char map[105][105];
int main() {cin.tie(0);cin >> n >> m;for (int i = 1; i <= n; ++i)for (int j = 1; j <= m; ++j)cin >> map[i][j];for (int i = 1; i <= n; ++i) {for (int j = 1; j <= m; ++j) {int x = 0;if (map[i][j] == '*') {if (map[i + 1][j] == '*')++x;if (map[i + 1][j - 1] == '*')++x;if (map[i + 1][j + 1] == '*')++x;if (map[i - 1][j - 1] == '*')++x;if (map[i - 1][j + 1] == '*')++x;if (map[i][j + 1] == '*')++x;if (map[i][j - 1] == '*')++x;if (map[i - 1][j] == '*')++x;if (x < 2 || x > 3) {cout << "Other";return 0;}} else {if (map[i + 1][j] == '*')++x;if (map[i + 1][j - 1] == '*')++x;if (map[i + 1][j + 1] == '*')++x;if (map[i - 1][j - 1] == '*')++x;if (map[i - 1][j + 1] == '*')++x;if (map[i][j + 1] == '*')++x;if (map[i][j - 1] == '*')++x;if (map[i - 1][j] == '*')++x;if (x == 3) {cout << "Other";return 0;}}}}cout << "Still life";return 0;
}

计算GPA

#include<iostream>
#include<string>using namespace std;int main() {string gpa;float count = 0 , len[2] = {0, 0};cin >> gpa;len[0] = gpa.size() + 1;for (int i = 0; i < len[0]; ++i)if (gpa[i] == 'A' || gpa[i] == 'B' || gpa[i] == 'C' || gpa[i] == 'D')len[1]++;for (int i = 0; i < len[0]; ++i) {if (gpa[i] == 'A')count = count + 4;else if (gpa[i] == 'B')count = count + 3;else if (gpa[i] == 'C')count = count + 2;else if (gpa[i] == 'D')count = count + 1;else if (gpa[i] == '+')count = count + 0.3;else if (gpa[i] == '-')count = count - 0.3;}float score = count / len[1];printf("%.2f", score);return 0;
}

九宫格键盘

#include <iostream>
#include <string>
using namespace std;int main() {string s;int count = 0, len;getline(cin, s);len = s.length();for (int i = 0; i < len; ++i) {if (s[i] == 'a' || s[i] == 'd' || s[i] == 'g' || s[i] == 'j' || s[i] == 'm' || s[i] == 'p' || s[i] == 't'|| s[i] == 'w' || s[i] == ' ')count++;else if (s[i] == 'b' || s[i] == 'e' || s[i] == 'h' || s[i] == 'k' || s[i] == 'n' || s[i] == 'q' || s[i] == 'u'|| s[i] == 'x')count += 2;else if (s[i] == 'c' || s[i] == 'f' || s[i] == 'i' || s[i] == 'l' || s[i] == 'o' || s[i] == 'r' || s[i] == 'v'|| s[i] == 'y')count += 3;else if (s[i] == 'z' || s[i] == 's')count += 4;}cout << count;return 0;
}

闯关升级

#include<iostream>
#include<algorithm>
using namespace std;int main() {int n, t, x, num_a = 0, num_b, ans, sum_a[100010], sum_b[100010];cin >> n >> t;//前缀和for (int i = 1; i <= n; ++i)cin >> x, sum_a[i] += sum_a[i - 1] + x;for (int i = 1; i <= n; ++i)cin >> x, sum_b[i] += sum_b[i - 1] + x;while (sum_b[num_b + 1] <= t && num_b + 1 <= n)num_b++;ans = max(ans, num_b);while (sum_a[num_a + 1] <= t && num_a + 1 <= n) {num_a++;while (sum_a[num_a] + sum_b[num_b] > t && num_b > 0)num_b--;ans = max(ans, num_a + num_b);}cout << ans << endl;return 0;
}

三倍游戏

#include <iostream>
using namespace std;
long long i, n, a[100001], c[100001], ans;
int main() {cin >> n;for (i = 1; i <= n; i++) {cin >> a[i];c[a[i] % 3]++;  // 计算每张卡片数字对3取余的余数相同的卡片个数}cout << min(c[1], c[2]) + c[0] / 2;        // 最高得分return 0;
}

救援争先

#include <iostream>
#include <algorithm>
using namespace std;int n;
const int maxn = 1010;
struct team {int leave, arrive, id;
} a[maxn];bool cmp(team a, team b) {if (a.arrive < b.arrive)return true;if (a.arrive == b.arrive) {if (a.leave < b.leave)return true;if (a.leave == b.leave)if (a.id < b.id)return true;}return false;
}int main() {cin >> n;for (int i = 1; i <= n ; ++i) {int h, m;char ch;cin >> h >> ch >> m;a[i].leave = h * 60 + m;cin >> h >> ch >> m;a[i].arrive = a[i].leave + h * 60 + m;a[i].id = i;}sort(a + 1, a + 1 + n, cmp);for (int i = 1; i <= n; ++i)cout << a[i].id << endl;return 0;
}

数字验证

#include <bits/stdc++.h>
using namespace std;
string s;
int cnt = 0;
int main() {cin >> s;if (s[0] == '+' || s[0] == '-') s = s.substr(1);if (s == ".") {cout << "Invalid";return 0;}for (int i = 0; i < s.size(); i ++) {if (s[i] == '.') {cnt ++ ;if (cnt > 1) {cout << "Invalid";return 0;}} else if (s[i] < '0' || s[i] > '9') {cout << "Invalid";return 0;}}cout << "Valid";return 0;
}

评测队列

#include <iostream>
using namespace std;int a[200005], b[200005], n;
long long ans, t;
int main() {cin >> n;for (int i = 1; i <= n; i++)cin >> a[i] >> b[i];ans = t = 0;for (int i = 1; i <= n; i++) {t += a[i];ans = max(ans, t);ans += b[i];}cout << ans;return 0;
}

买二送一

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long long sum;
int n, t;
bool cmp(int a, int b) {return a > b;
}
int main() {vector<int> v;cin >> n;for (int i = 0; i < n; ++i) {cin >> t;v.push_back(t);}sort(v.begin(), v.end(), cmp);if (v.size() >= 3) {while (v.size() >= 3) {sum += v[0] + v[1];if (v.size() >= 3)v.erase(v.begin(), v.begin() + 3);}}for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {sum += *it;}cout << sum;return 0;
}

考试排名

#include <iostream>
#include <algorithm>
using namespace std;int n;
struct classes {int a[4];double b[4];int num, id;
} cls[10005];bool cmp(classes x, classes y) {if (x.b[0] > y.b[0]) return true;if (x.b[0] == y.b[0]) {if (x.b[1] > y.b[1]) return true;if (x.b[1] == y.b[1]) {if (x.b[2] > y.b[2]) return true;if (x.b[2] == y.b[2]) {if (x.b[3] > y.b[3]) return true;if (x.b[3] == y.b[3]) {if (x.num > y.num) return true;if (x.num == y.num) {if (x.id < y.id) return true;}}}}}return false;
}int main() {cin.tie(0);cin >> n;for (int i = 1; i <= n; i ++) {string s;cin >> s;int len = s.size();for (int j = 0; j < len; j ++) {int t = s[j] - 'A';cls[i].a[t] ++;}for (int j = 0; j < 4; j ++) {cls[i].b[j] = cls[i].a[j] * 1.0 / len;}cls[i].num = len;cls[i].id = i;}sort(cls + 1, cls + 1 + n, cmp);for (int i = 1; i <= n; i ++) cout << cls[i].id << ' ';return 0;
}

巧妙的数

#include <iostream>
using namespace std;int main() {bool mt[10];int a[1010], n;char ch;while (cin >> ch) {a[++n] = ch - '0';mt[a[n]] = true;}for (int i = 2; i <= 9; ++i) {if (mt[i]) {int r = 0;for (int j = 1; j <= n; j ++) {r = (r * 10 + a[j]) % i;}if (r != 0) {cout << "not clever";return 0;}}}cout << "clever";return 0;
}

三倍子串

#include <iostream>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;int main() {char str[1000005];while (scanf("%s", str) != EOF) {long long sum[3] = {0};int s = 0;int n = strlen(str);for (int i = 0; i < n; i++) {s += str[i] - '0';s %= 3;sum[s]++;}long long ans;ans = (sum[0] + 1) * sum[0] / 2 + sum[1] * (sum[1] - 1) / 2 + sum[2] * (sum[2] - 1) / 2;printf("%lld\n", ans);}return 0;
}

没有考试的天数

#include <iostream>
using namespace std;int gcd(int x, int y) {if (y == 0) return x;return gcd(y, x % y);
}int main() {int n, a, b, c;cin >> n >> a >> b >> c;int d = a / gcd(a, b) * b;int e = b / gcd(b, c) * c;int f = c / gcd(c, a) * a;int g = d / gcd(d, c) * c;cout << n - (n / a + n / b + n / c) + (n / d + n / e + n / f) - n / g;return 0;
}

上海市计算机学会竞赛平台二星级挑战相关推荐

  1. 上海市计算机学会竞赛平台三星级挑战

    上海市计算机学会竞赛平台 | 2022 三星级挑战 最大回撤 最后一击 平衡点 栈的判断 排队安排 逆波兰式 股票市场 城市的中心 伙伴 两数之和 阶乘求和(Python3.6) 连乘问题 随机性验证 ...

  2. 上海市计算机学会竞赛平台一星级挑战

    上海市计算机学会竞赛平台 | 2022 一星级挑战 奖牌的数量 数人数 盈亏问题 方舱医院 数球数 切蛋糕 时间格式 数字加密 打渔还是晒网 竞选班长 做烧饼 植树造林 促销骰子 逢七必过 回文数的判 ...

  3. 上海市计算机学会竞赛平台(iai.sh.cn)2023三月月赛(丙组)解题报告

    前言 总的来说这次的丙组偏简单,像我这个菜鸟都能在赛场上AK,之前的比赛后两题会有递归搜索并且要有一定的数学思维,但这次并没有什么高深的算法或者数学思维. 一到三题不用多说,是模拟题,可能带点技巧.从 ...

  4. 屏幕比例c++ 上海市计算机学会竞赛平台8月月赛第2题

    题目描述 现实生活中,我们一般把屏幕的宽度和高度的比例,称为屏幕比例,或称为屏幕长宽比.例如分辨率为 1920 * 1080 的屏幕,其长宽比即为 16 : 9 现给定一个屏幕的分辨率,以 X * Y ...

  5. 上海市计算机学会竞赛平台.2023年1月月赛丙组

    T1 实验日志 题目描述 小爱正在完成一个物理实验,为期n天,其中第i天,小爱会记录 a i a_i ai​ 条实验数据在实验日志中. 已知小爱的实验日志每一页最多纪录m条数据,每天做完实验后他都会将 ...

  6. 上海市计算机学会竞赛 2023.1 丙组月赛

    上海市计算机学会竞赛 2023.1 丙组月赛 T1 实验日志 题目描述 小爱正在完成一个物理实验,为期 n n n天,其中第 i i i天,小爱会记录 a i a_i ai​ 条实验数据在实验日志中. ...

  7. 上海市计算机学会-买二送一

    上海市计算机学会竞赛平台 | YACS 题目描述 有n 本书,第 i本书的价格为 ai​,小爱想把这些书全部买回家.现在正有一个买二送一的促销活动,即,凡是购买两本书,就可以免费带走第三本书,只要免费 ...

  8. 上海市计算机学会2022年10月月赛丙组解题报告

    上海市计算机学会2022年10月月赛丙组解题报告 直角三角形的判定 题目描述 给定三个正整数表示三角形的三条边,请判定它是否为直角三角形 输入格式 第一行:三个整数 a,b 与 c 输出格式 若可以构 ...

  9. 上海市计算机学会月赛 2022年9月月赛丙组

    上海市计算机学会月赛 2022年9月月赛丙组 这次题目真的衡水 矩形的周长与面积 机会成本 三色排序 阶乘尾数 前序中序转后序 这次题目真的衡水 文章拖了好久忘记发了 明天初赛祝各位考试顺利有一个好的 ...

最新文章

  1. 解析大型.NET ERP系统 多国语言实现
  2. 菜鸟学SSH(十二)——Hibernate与Spring配合生成表结构
  3. linux下,redis 3.2.1双节点集群安装部署
  4. 依赖注入与Unity
  5. python写一个表白程序-用Python做一个情人节表白神器
  6. C语言 *n++和(*n)++的区别
  7. tkinter回调异常_使用matplotlib保存动画时Tkinter回调出现异常
  8. TF学习——TF之API:TensorFlow的高级机器学习API—tf.contrib.learn的简介、使用方法、案例应用之详细攻略
  9. Vue—上手实践—环境搭建
  10. 通过 nginx-proxy 实现自动反向代理和 HTTPS
  11. 【CodeForces - 689D】Friends and Subsequences(RMQ,二分 或单调队列)
  12. 2018: 跑图(深搜)
  13. 软件工程需求分析文档模板
  14. c语言生成 pdf文件,使用PDFLib生成PDF文档(C语言版)--使用指导
  15. 服务器音频文件缓存,音频文件如何缓存到本地,和播放缓存到本地的音频文件...
  16. 工作网络计算机显示不完全,win10网络共享,计算机显示不全?
  17. 「WinddowInsets(二)」我们能用WindowInsets做什么?
  18. 面向对象设计原则实践:之四.里氏代换原则
  19. 阿里巴巴二重身ABBC Coin虚涨逾100%
  20. PHP树结构的应用,实现树状结构的两种方法-PHP教程,PHP应用

热门文章

  1. 学习Redis这一篇就够了
  2. 通用异步收发器UART
  3. javascript 获取括号中内容 正则表达式
  4. Androidstudio的约束布局,最新Android高级面试题汇总
  5. Springboot毕设项目个性相册网站52jtb(java+VUE+Mybatis+Maven+Mysql)
  6. Rhyme/Intellij idea 工作窗口切换快捷键,摆脱鼠标的束缚
  7. 易买网更多新闻代码_新闻 | 1018MAMAMOO公布了颂乐与华莎主题海报等更多资讯
  8. android QQ文字提取,手机QQ V7.1.8文字提取新功能怎么用?手机QQ文字提取教程
  9. python字符串索引局部变量_4. 列表一学完,Python 会一半,滚雪球学 Python【七日打卡】...
  10. ae安装失败计算机丢失,AE安装失败的原因你真知道吗 ?正确的安装AE软件