23 暑假友谊赛 No.3
23 暑假友谊赛 No.3
Problem - B - Codeforces
贪心吧,每次看哪块瓷砖划算就尽量多的放哪块
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n,m,x,y; cin >>n >> m >> x >> y; vector<string> g(n); for(auto &i : g) cin >> i; int ans = 0; for(int i =0;i < n;i ++){ for(int j = 0;j < m;j ++){ if(x * 2 <= y && g[i][j] == '.'){ ans += x; }else{ int k = 0; while(g[i][j] == '.' && j < m){ k++, j++; } ans += k / 2 * y + k % 2 * x; } } } cout << ans << endl; } return 0; }
Problem - C - Codeforces
比较两个端点就行了
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int l1,l2,r1,r2; cin >> l1 >> r1 >> l2 >> r2; if(l1 >= r2){ cout << r1 << ' ' << l2 << endl; }else cout << l1 << ' ' << r2 << endl; } return 0; }
Problem - D - Codeforces
推出\(a^2=2\times c -1\)就好做了,直接去枚举就行
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n; cin >> n ; int ans = 0; for(int i = 3;i <= n;i++){ int m = (i * i + 1) / 2; if(m > n) break; if(2 * m - 1 == i * i) ans ++; } cout << ans << endl; } return 0; }
Problem - E - Codeforces
一个桶计数即可,然后取最大值.
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n; cin >> n; vector<int> a(n),t(110); for(auto &i : a) { cin >> i; t[i]++; } int ans = *max_element(t.begin(), t.end()); cout << ans << endl; } return 0; }
Problem - G - Codeforces
看比最小数大的有多少
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n; cin >> n ; vector<int> a(n); for(auto &i : a) { cin >> i; } int mi = *min_element(a.begin(), a.end()); int ans = 0; for(auto i : a) ans += (i > mi); cout << ans << endl; } return 0; }
Problem - I - Codeforces
分类讨论:
- m小于平均数的话,全给一个人就行了
- 大于的话,多出来的joker牌小于其他k-1个人就-1,能整除k-1个人就给k-1个人平均分配,然后m减去这个平均值,不能整除,说明有几张刚好多出来,m在那基础上再-1就行了
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n,m,k; cin >> n >> m >> k; int card = n / k; if(m <= card){ cout << m << endl; }else{ m -= card; k--; if(m < k){ cout << card - 1 << endl; }else if(m % k == 0){ cout << card - m / k << endl; }else cout << card - m / k - 1 << endl; } } return 0; }
Problem - J - Codeforces
唉,写了一堆判断,我考虑的真麻烦,懒得写了,建议看我学长的
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n,k; cin >> n >> k; if(n % 2 == 0){ if(k >= n ){ if(k % n == 0) cout << n << endl; else cout << k % n << endl; }else{ cout << k << endl; } }else if(k * 2 <= n){ cout << k << endl; }else{ int p = (k - 1) / (n / 2); int now; if(k % n == 0) now = n; else now = k % n; if((now + p) % n == 0) cout << n << endl; else cout << (now + p) % n << endl; } } return 0; }
Problem - L - Codeforces
唉,破构造题,刚开始dfs写超时,后来打表找规律又找错了,麻了
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n; cin >> n; for(int i = 1;i < n;i ++){ for(int j = i + 1;j <= n;j ++){ if(2 * (j - i) == n) cout << 0 << ' '; else if(2 * (j - i) < n) cout << 1 << ' '; else cout << -1 << ' '; } } cout << endl; } return 0; }
Problem - M - Codeforces
双指针从两边求前缀后缀和,相等的时候记录一下就行了
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> PII; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n; cin >> n ; vector<int> a(n); for(auto &i : a) cin >> i; int A = a[0],B = a.back(), ans = 0; for(int i = 0, j = n - 1;i < j;){ if(A == B) ans = (i + 1) + (n - j); if(A > B){ j--; B += a[j]; }else{ i++; A += a[i]; } } cout << ans << endl; } return 0; }
总结
唉,刚开始编译器出问题了,半天没响应,本来最简单的签到题结果没看范围又wa了一发,后面又被那两只破猫换位置考虑了一堆写烦了,还有那个d题,刚开始读假了,没看到还要符合直角三角形,wa1发,后面那个破构造题,写个dfs超时,打表找规律找错,麻了,惹,感觉不如多来点二分贪心图论的题,补题看心情了,反正是越想越气\(:<\)
总结的总结
加训
本文作者:Ke_scholar
本文链接:https://www.cnblogs.com/Kescholar/p/17604319.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
标签:
,
,
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步