算法模板(持续更新)
板子
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162#include <bits/stdc++.h>#define x first#define y second#define endl '\n'#define Max(a, b) a > b? a : b#define Min(a, b) a < b? a : busing namespace std;using ll = long long;using ull = unsigned long long;using i128 = __int128;using PII = pair<int, int>;int read(){ int x = 0, f = 1; //快读 char ch = getchar(); while (ch < '0' ...
信阳师范大学算法工作室招新中~
你是否想在大学发现一个更精彩的新世界?
你是否对自己的天赋充满信心?(尤其是逻辑能力或数学思维)
你是否想体验最极致的编程乐趣?
你是否想找一群志同道合的朋友一起奋斗?
那么,来加入XYNU的算法工作室吧!
——————————————————————————————————
什么是ACM?
ACM 全称 ACM-ICPC,原本专指国际大学生程序设计竞赛(International Collegiate Programming Contest)。
由国际计算机学会(Association for Computing Machinery,简称 ACM )赞助与冠名。虽然从 2018 年起 ICPC 从 ACM 名下独立出来,但还是延续传统继续称之为 ACM 竞赛。
比赛赛制为 5 小时内三人一队利用一台计算机编程解决算法问题。其余类似赛制的比赛也常用 ACM 指代,泛指种种大学生算法竞赛。
进入工作室后能干什么?
我们关注的算法竞赛主要包括:
国际大学生程序设计竞赛(ICPC)
中国大学生程序设计竞赛(CCPC)
蓝桥杯程序设计竞赛
团体程序设计天梯赛
注:ICPC 和 CCPC ...
牛客周赛 Round 100 题解
A. 小红的双排列
签到,\(1-n\) 每个数输出两次即可。
code:
1234567891011121314151617181920212223242526272829303132333435363738#include <bits/stdc++.h>#define x first#define y second#define endl '\n'using namespace std;using ll = long long;using i128 = __int128; using PII = pair<int, int>;i128 read(){i128 x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if (ch == '-') f = -1;ch = getchar();}while(ch >= '0' && ch ...
牛客周赛 Round 99 题解
非常简单的一场周赛,可惜 \(D\) 读错题浪费一个多小时导致赛后 \(3\) 分钟才过 \(F\)。
A. Round 99
签到
code:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#include <bits/stdc++.h>#define x first#define y second#define endl '\n'using namespace std;using ll = long long;using i128 = __int128; using PII = pair<int, int>;i128 read(){i128 x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-') f = -1;ch = g ...
AtCoder Beginner Contest 413 题解
A. Content Too Large
签到,计算出来物品体积的总和,与袋子的大小做对比即可。
code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344#include <bits/stdc++.h>#define x first#define y second#define endl '\n'using namespace std;using ll = long long;using PII = pair<int, int>;int read(){int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-') f = -1;ch = getchar();}while (ch >= '0' &&am ...
牛客小白月赛119题解
A. 来!选!队!长
签到题。
由于队长的战力要乘以二,因此‘我’的队伍最大战力为 \(r1=a_1 \times 2+a_2+a_3+a_4+a_5\),好友队伍的最小战力为 \(r2=b_1+b_2+b_3+b_4+b_5 \times 2\)。
题目问是否有可能使得‘我’的队伍战力大于好友队伍战力,因此只需判断 \(r1 > r2\) 这个条件是否成立即可。
code:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#include <bits/stdc++.h>#define x first#define y second#define endl '\n'using namespace std;using ll = long long;using PII = pair<int, int>;int read(){int x = 0, f = 1;char ch = getchar();whi ...
牛客周赛 Round 75 题解
A. 小红的正整数计数
签到
code:
12345678910111213141516171819#include <bits/stdc++.h>using namespace std;int l, r;int main(){ cin >> l >> r; int res = 0; for (int i = l; i <= r; i++) if (i % 2 == 0) res++; cout << res << endl; return 0;}
B. 小红的双生串
分别统计前半段和后半段出现最多的字符,再把整个字符串修改成只有这两个字符。
code:
12345678910111213141516171819202122232425#include <bits/stdc++.h>using namespace std;string s;int main(){ cin >> ...
Codeforces Round 996 (Div. 2) 题解
A. Two Frogs
当两个青蛙之间的距离为 \(1\) 时,此时先跳的青蛙最终会被逼到角落。
不难发现,两个青蛙跳跃的次数相同时,它们之间距离的奇偶性是不变的。因此,若两青蛙初始距离为奇数,则它们距离为 \(1\) 时 \(Alice\) 先跳。若两青蛙初始距离为偶数,此时 \(Alice\),先跳一次,情况转变成 \(Bob\) 先手,并且它们之间的距离为奇数,所以当距离为 \(1\),时,\(Bob\) 先跳。
code:
123456789101112131415161718192021222324252627282930313233#include <bits/stdc++.h>#define int long long#define x first#define y second#define endl '\n'using namespace std;typedef pair<int, int> PII;const int N = 200010;int T;int n, a, b;signed main(){ ...
牛客周赛 Round 76 题解
A. 小红出题
签到
code:
12345678910111213141516171819#include <bits/stdc++.h>using namespace std;int n;int main(){ cin >> n; int res = 0; for (int i = 1; i <= n; i++) if (i % 7 != 6 && i % 7) res += 3; cout << res << endl; return 0;}
B. 串串香
一个字符串中出现次数最多的子串长度一定是 \(1\),因此只需要统计出现次数最多的字符即可。
code:
123456789101112131415161718192021222324#include <bits/stdc++.h>using namespace std;int n;string s;int main(){ ...
AtCoder Beginner Contest 388 题解
A. ?UPC
签到
code:
1234567891011121314#include <bits/stdc++.h>using namespace std;string s;int main(){ cin >> s; cout << s[0] << "UPC" << endl; return 0;}
B. Heavy Snake
暴力枚举
code:
1234567891011121314151617181920212223#include <bits/stdc++.h>using namespace std;const int N = 110;int n, d;int t[N], l[N];int main(){ cin >> n >> d; for (int i = 0; i < n; i++) cin >> t[i] >> l[i]; for (int i = 1; ...