标题
增加 1 行删除 1 行
1GY 5.3 比赛总结15.3 比赛总结
正文
增加 33 行删除 32 行
1234567896 行未改动161718192021222324252 行未改动28293031323334353637383940414243444546473 行未改动515253545556575859606162636465666768697071727374757677787980818283848586878889909192939458 行未改动1531541551561571581591601611625 行未改动1681691701711721731741751761772 行未改动18018118218318418518618718836 行未改动# GY 5.3 比赛总结## 1 扑克 Poker评价:普通·橙考点:排序(sort) & 去重(unique)[考试题目链接](https://www.luogu.com.cn/problem/T758084?contestId=324948)[标准题目链接](https://www.luogu.com.cn/problem/P13733)6 行未改动vector <int> a(n);for (int i = 0;i < n;i++) cin >> a[i];sort(a.begin(),a.end());auto new_end = unique(a.begin(),a.end());a.erase(new_end,a.end()); // 可加可不加,随你n = a.size(),rlen = 1;```接下来,定义变量 $rlen$ 存储最长顺子长度,枚举 vector ,分类讨论:1. $a_i - 1 = a_{i - 1}$(即顺子)2 行未改动2. $a_i - 1 \neq a_{i - 1}$(即非顺子,断连)判断 $rlen$ 是否大于 $k$ ;若大于等于,已经有解,直接输出 $Yes$ 并结束程序;若小于,将 $rlen$ 归 $1$ ,重新计数。```cppfor (int i = 1;i < n;i++){if (a[i - 1] == a[i] - 1) rlen++;else{if (rlen >= k){cout << "Yes\n";return 0;}rlen = 1;}}```最后,还要再判断 $rlen$ 是否大于 $k$ ,因为最后还有一段未检测的顺子,还要再检测一遍。```cpp3 行未改动综合代码:```cpp#include <bits/stdc++.h>using namespace std;const int N = 3e5 + 3;int n,k,rlen;int main(){ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);cin >> n >> k;vector <int> a(n);for (int i = 0;i < n;i++) cin >> a[i];sort(a.begin(),a.end());auto new_end = unique(a.begin(),a.end());a.erase(new_end,a.end());n = a.size(),rlen = 1;for (int i = 1;i < n;i++){if (a[i - 1] == a[i] - 1) rlen++;else{if (rlen >= k){cout << "Yes\n";return 0;}rlen = 1;}}if (rlen >= k) cout << "Yes\n";else cout << "No\n";return 0;}```## 2 相聚 いっしょ评价:顶级·黄考点:贪心(Greedy alogorithm) & 动态规划(DP)[考试题目链接](https://www.luogu.com.cn/problem/T758085?contestId=324948)[标准题目链接](https://www.luogu.com.cn/problem/P11686)58 行未改动#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 3,M = 503;struct Swap { int a,b; }t[N];bool cmp(Swap x,Swap y) { return x.a < y.a; }int n,m,dp[M][N],l;int main(){ios::sync_with_stdio(0);5 行未改动{for (int j = 1;j < t[i].a;j++) dp[i][j] = dp[i - 1][j];for (int j = t[i].a;j <= n;j++) dp[i][j] = max(dp[i - 1][j],dp[i][j - t[i].a + t[i].b] + t[i].b);}l = 1;for (int i = 1;i <= n;l = dp[m][i] + i + 1,i++){for (int j = l;j <= min(dp[m][i] + i,n);j++) cout << i << "\n";if (dp[m][i] + i >= n) break;}2 行未改动```## 4 雪球2 Snowball2评价:顶级·黄考点:分治(partition) & 前缀和(prefix sum)[考试题目链接](https://www.luogu.com.cn/problem/T758086?contestId=324948)[标准题目链接](https://www.luogu.com.cn/problem/P13734)36 行未改动123456789101112131415161718196 行未改动2627282930313233342 行未改动37383940414243444546474849505152533 行未改动57585960616263646566676869707172737475767778798081828384858687888990919293949558 行未改动1541551561571581591601611621631645 行未改动1701711721731741751761771782 行未改动18118218318418518618718818936 行未改动主编:[yqx34](https://www.luogu.com.cn/user/1802948)制作人员:[yqx34](https://www.luogu.com.cn/user/1802948)、[yyq3](https://www.luogu.com.cn/user/1803226)、[Starlight_Footprint](https://www.luogu.com.cn/user/1359067)# 5.3 比赛总结## 0 赛后感好难啊!真的是太难了……不过还好,总共 $10$ 人,我拿第 $5$ 名。~~但只有 82 分……~~看到结果的那一刻我震惊了!## 1 扑克 Poker评价:普通·橙考点:排序(Sorting) & 去重(Unique)[考试题目链接](https://www.luogu.com.cn/problem/T758084?contestId=324948)[标准题目链接](https://www.luogu.com.cn/problem/P13733)6 行未改动vector <int> a(n);for (int i = 0;i < n;i++) cin >> a[i];sort(a.begin(),a.end());auto new_end = unique(a.begin(),a.end());a.erase(new_end,a.end());```接下来,定义变量 $rlen$ 存储最长顺子长度,枚举 vector ,分类讨论:1. $a_i - 1 = a_{i - 1}$(即顺子)2 行未改动2. $a_i - 1 \neq a_{i - 1}$(即非顺子,断连)判断 $rlen$ 是否大于 $k$ ;若大于等于,已经有解,直接输出 $Yes$ 并结束程序;若小于,将 $rlen$ 归 $1$ ,重新计数。```cppfor (int i = 1;i < (int)a.size();i++){if (a[i] - 1 == a[i - 1]) rlen++;else if (rlen >= k){cout << "Yes\n";return 0;}else rlen = 1;}```最后,还要再判断 $rlen$ 是否大于 $k$ ,因为最后还有一段未检测的顺子,还要再检测一遍。```cpp3 行未改动综合代码:```cpp#include <bits/stdc++.h>using namespace std;int main(){ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);int n,k,rlen = 1;cin >> n >> k;vector <int> a(n);for (int i = 0;i < n;i++) cin >> a[i];sort(a.begin(),a.end());auto new_end = unique(a.begin(),a.end());a.erase(new_end,a.end());for (int i = 1;i < (int)a.size();i++){if (a[i] - 1 == a[i - 1]) rlen++;else if (rlen >= k){cout << "Yes\n";return 0;}else rlen = 1;}if (rlen >= k) cout << "Yes\n";else cout << "No\n";return 0;}```## 2 相聚 いっしょ评价:顶级·黄考点:贪心(Greedy Algorithm) & 动态规划(DP)[考试题目链接](https://www.luogu.com.cn/problem/T758085?contestId=324948)[标准题目链接](https://www.luogu.com.cn/problem/P11686)58 行未改动#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 3,M = 503;struct Swap { int a,b; }t[N];int n,m,dp[M][N];bool cmp(Swap x,Swap y) { return x.a < y.a; }int main(){ios::sync_with_stdio(0);5 行未改动{for (int j = 1;j < t[i].a;j++) dp[i][j] = dp[i - 1][j];for (int j = t[i].a;j <= n;j++) dp[i][j] = max(dp[i - 1][j],dp[i][j - t[i].a + t[i].b] + t[i].b);}for (int i = 1,l = 1;i <= n;l = dp[m][i] + i + 1,i++){for (int j = l;j <= min(dp[m][i] + i,n);j++) cout << i << "\n";if (dp[m][i] + i >= n) break;}2 行未改动```## 4 雪球2 Snowball2评价:顶级·黄考点:分治(Partition) & 前缀和(Prefix Sum)[考试题目链接](https://www.luogu.com.cn/problem/T758086?contestId=324948)[标准题目链接](https://www.luogu.com.cn/problem/P13734)36 行未改动