2025 3.17~3.23
牛客周赛 85 A 签到 1234567891011#include <bits/stdc++.h>using namespace std;int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int n; cin >> n; cout << (n%2 ? "kou\n" : "yukari\n"); return 0;} B 贪心 由题目可知,小红和小紫的拿取元素的倾向都是拿尽可能小的元素 因此直接对数组升序排序,然后遍历数组对x进行操作即可 12345678910111213141516171819202122#include <bits/stdc++.h>using namespace std;const int maxn = 1e5+1;int arr[maxn];int main(void){ ios::sync_with_...
2025 3.10~3.16
牛客周赛84 续上周 D 赛时用的数学方法,花的时间和代码量比较多。差分我写得少,这里用题解的差分方法补个题 用差分数组对每个k区间做修改,然后求和以及相邻数字绝对值差对陡峭值的贡献即可 123456789101112131415161718192021222324#include <bits/stdc++.h> using namespace std;const int maxn = 1e6+1;int t[maxn],d[maxn];int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int n,k,ans=0; cin >> n >> k; string s; cin >> s; for(int i=1,j=k;j<=n;i++,j++){ d[i]++; d[j]--; } t[0]=0; for(int i=1;i...
2025 3.3~3.9
牛客月赛 111 A 贪心,田鸡的最大的a比齐威王次大的v大,田鸡的次大的a比齐威王最小的v大就能赢 123456789101112131415161718#include <bits/stdc++.h>using namespace std;int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int v[3],a[3]; for(int i=0;i<3;i++) cin >> v[i]; for(int i=0;i<3;i++) cin >> a[i]; sort(v,v+3); sort(a,a+3); if(a[2] > v[1] && a[1] > v[0]) cout << "Yes\n"; else cout << "No\n"; ...
2025 2.24~3.2
牛客周赛81 A 题目 签到 代码 12345678910111213#include <bits/stdc++.h>using namespace std;int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int a,b,c; cin >> a >> b >> c; if(a==b && b==c) cout <<"Yes\n"; else if(a+1==b && b+1==c) cout << "Yes\n"; else cout << "NO\n"; return 0;} B 题目 一颗完全二叉树,如果每个节点的两个子节点都不小于它,那么这称颗二叉树是“平衡的”。数据量不大,把树储存在二维数组里,逐节点判断即可 如果某个节点满足G[i][j...
2025 2.10~2.16
牛客周赛80 A 题目 签到 代码 123456789101112#include <bits/stdc++.h>using namespace std;int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int x,y; cin >> x >> y; if(x >= y) cout << x-y << '\n'; else cout << "quit the competition!\n"; return 0;} B 题目 降序排序,相邻两项之间相减,取绝对值,求和即可 代码 123456789101112131415161718192021222324#include <bits/stdc++.h>using namespace std;const int maxn = 2e5+1;bool cp...
2025 2.3~2.9
牛客寒假训练营1 大家都报了训练营呐,那我也报一个 ^v^(虽晚不亏) 补一下之前的 A 题目 这题考察素数。由题目得,ai不超过1e9,因此如果给的数有1就输入-1(1和任何数都构成倍数关系),否则输出任意一个比1e9大的素数、 那比1e9大的素数怎么找呢? 新开一个cpp,用埃氏筛把这个数找到,是999999937,CV 代码 埃氏筛 1234567891011121314151617181920212223#include <bits/stdc++.h>#define int long longusing namespace std;const int maxn=1e9+5;bool visi[maxn];vector <int> prime;void sushu(){ for(int i=2;i*i<maxn;i++) if(!visi[i]) for(int j=i*i;j<maxn;j+=i) visi[j] = true; for(int ...
2025 1.20~1.26
codeforces 991 div.3 A 题目 字符串处理,题意大概是:给你一个数字,问你有多少个完整的单词的字母数之和不超过这个数字。很简单的字符串题,运用字符串的size()函数即可。 代码 123456789101112131415161718192021222324#include <bits/stdc++.h>using namespace std;int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin >> t; while(t--){ int n,m,sum=0; string s; cin >> n >> m; while(n--){ cin >> s; int len = s.size(); m-=len; ...
2024下 第18周12.30~1.5
codeforces 995 div3 A 题目 贪心,要使m-s差最大化,就让每个大于零的ai-b(i+1 )相加,并加上a[n-1],就是最大值 代码 123456789101112131415161718192021222324252627#include <bits/stdc++.h>using namespace std;int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin >> t; while(t--){ int a[101],b[101],cache,n,sum=0; cin >> n; for(int i=0;i<n;i++){ cin >> cache; a[i]=cache; } for(int i=0;i<n...
2024下 第17周12.23~12.29
codeforces 993 div4 A 题目 给你一个n,问你有多少有序数对(a,b)满足a+b=n? 其实就是n-1 代码 1234567891011121314#include <bits/stdc++.h>using namespace std;int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t,n; cin >> t; while(t--){ cin >> n; cout << n-1 << '\n'; } return 0;} B 题目 这个人在店铺外面看窗上的字母是"qwq",问你在店铺里面看窗子上是什么字母? 逆序输出,q变p,p变q,w不变 代码 12345678910111213141516171819#include <bits/stdc++...
2024下 第16周12.16~12.22
codeforces 988 div.3 A 题目 找相同的数字,有点像天天爱消除,两个相同的数字就可以消掉,用个数组记录数字出现的次数就ok。这题数据很小,什么方法都行 代码 1234567891011121314151617181920212223242526#include <bits/stdc++.h>using namespace std; int t,score,n,cache,a[21]; int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin >> t; while(t--){ cin >> n; fill_n(&a[0],21,0);score=0; for(int i=0;i<n;i++){ cin >> cache; a[cache-1]++; ...