训练情况
赛后反思
模拟题差点红温,差一道字符串模拟题AK
A题
问一个数 \(a\) 加多少后的个位数变成 \(b\),取出 \(a\) 的个位数,再用 \(b\) 去减,如果小于零答案再加十。
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'using namespace std;void solve(){int a,b; cin>>a>>b;int ans = b-a%10;if(ans<0) ans += 10;cout<<ans<<endl;
}signed main(){// int T; cin>>T; while(T--)solve();return 0;
}
B题
巨大无比分类讨论,分为奇偶性不同和同奇和同偶三种情况,奇偶性不同计算离零的距离再+1就是答案,相同计算两数距离,再特判一下一端为零。
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'using namespace std;void solve(){int a,b; cin>>a>>b;if(a==0){cout<<(b-1)/2<<endl;return;} else if(b == 0){cout<<(a-1)/2<<endl;return;}if(a%2==b%2){cout<<abs(b-a)/2-1<<endl;} else if(a&1){cout<<(b-1)/2+1+a/2<<endl;} else if(b&1){cout<<(a-1)/2+1+b/2<<endl;}
}signed main(){// int T; cin>>T; while(T--)solve();return 0;
}
C题
直接模拟 \(x^2 \mod 10000\),进行 \(k-1\) 次就是答案,直接输出
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'using namespace std;void solve(){int x,c,k;cin>>x>>c>>k;for(int i = 1;i<k;i++){x = (x*x+c)%10000;}cout<<x<<endl;
}signed main(){// int T; cin>>T; while(T--)solve();return 0;
}
D题
遍历数列,找到 \(\le 15\) 的元素先插入新数列,之后全部处理完再插入 \(> 15\) 的元素
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'using namespace std;void solve(){int n; cin>>n;vector<int> a(n + 1);for(int i = 1;i<=n;i++) cin>>a[i];vector<int> b;for(int i = 1;i<=n;i++){if(a[i] <= 15) b.push_back(a[i]);}for(int i = 1;i<=n;i++){if(a[i] > 15) b.push_back(a[i]);}for(int i = 0;i<b.size();i++){cout<<b[i]<<" ";}
}signed main(){// int T; cin>>T; while(T--)solve();return 0;
}
E题
巨大无比的模拟题,计算循环的起始和终止条件比较麻烦,我们先处理横杠部分,再处理箭头的上半部分,下半部分直接对称过来即可。
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'using namespace std;void solve(){int n,m,k; cin>>n>>m>>k;char s[n+3][m+3];for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++) s[i][j] = 0;for(int i = (n+1)/2-(k-1)/2;i<=(n+1)/2+(k-1)/2;i++){for(int j = 1;j<=m-(n+1)/2;j++){s[i][j] = '#';}}for(int i = 1;i<=(n+1)/2;i++){for(int j = m-(n+1)/2+1;j<=m;j++){if(i>=(j-m+(n+1)/2)) s[i][j] = '#';}}for(int i = (n+1)/2;i<=n;i++){for(int j = m-(n+1)/2+1;j<=m;j++){s[i][j] = s[i-(i-(n+1)/2)*2][j];}}for(int i = 1;i<=n;i++){for(int j = 1;j<=m;j++){if(s[i][j]=='#') cout<<s[i][j];else cout<<".";}cout<<endl;}
}signed main(){// int T; cin>>T; while(T--)solve();return 0;
}
F题
先求列的和,再取最大值,从右往左找到第一个最大值的列,再取这个列的行取最大值并计数即可
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'using namespace std;void solve(){int n,m; cin>>n>>m;vector<vector<int>> a(n + 1,vector<int>(m + 1));vector<int> sum(m + 1);int masum = 0;for(int i = 1;i<=n;i++){for(int j = 1;j<=m;j++){cin>>a[i][j];sum[j] += a[i][j];masum = max(masum,sum[j]);}}int pos = m;for(int i = m;i;i--){if(sum[i] == masum){pos = i;break;}}int maa = 0;for(int i = 1;i<=n;i++){maa = max(maa,a[i][pos]);}int ans = 0;for(int i = 1;i<=n;i++){if(a[i][pos]==maa) ans++;}cout<<maa<<" "<<ans<<endl;
}signed main(){// int T; cin>>T; while(T--)solve();return 0;
}
G题
不知道为什么错了最后三个点,我们先对节拍进行计数,维护一个flag表示是否在括号内,遇到左括号计数器+1并改变flag,右括号改变flag,如果不在括号内并且不是 '
计数器加一,接下来我们计算连续的 L,R,L',R'
我们先判断较长的两个 L',R'
使用四个变量表示当前的连续次数,答案取连续最大值即可
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'using namespace std;void solve(){string s; int opt; cin>>s>>opt;int n = s.size();int ans = 0,a=0,b=0,c=0,d=0;bool flag = false;int aa=0,bb=0,cc=0,dd=0;for(int i = 0;i<n;i++){if(s[i] == '(') ans++,flag=true;else if(s[i] == ')') flag=false;else if(!flag){if(s[i]!='\'') ans++;}if(i!=n-1&&s.substr(i,2) == "L\'"){bb++; if(!flag) aa=0,cc=0,dd=0;}else if(i!=n-1&&s.substr(i,2)=="R\'"){dd++; if(!flag) aa=0,bb=0,cc=0;}else if(s[i] == 'L'){aa++; if(!flag) bb=0,cc=0,dd=0;}else if(s[i] == 'R'){cc++; if(!flag) aa=0,bb=0,dd=0; }a = max(aa,a);b = max(bb,b);c = max(cc,c);d = max(dd,d);}cout<<ans<<endl;if(opt) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}signed main(){// int T; cin>>T; while(T--)solve();return 0;
}
H题
直接模拟维护这个数列的变换操作,先求列的最大值和最小值,之后再全部遍历列,遇到相同的这个列的所有元素取出来之后,置零。最后对取出来的数进行排序,再按照题目要求,第奇数行从左往右,第偶数行从右往左,遇到零的位置放回去,进行 \(k\) 次即可
#include <bits/stdc++.h>
#define int long long
#define endl '\n'using namespace std;const int N = 53;int n,m,k;
int a[N][N];void op(){int ma = 0;int mi = LONG_LONG_MAX;int sumc[N]; for(int i = 1;i<=m;i++) sumc[i] = 0;for(int i = 1;i<=n;i++){for(int j = 1;j<=m;j++){sumc[j]+=a[i][j];}}for(int i = 1;i<=m;i++){ma = max(ma,sumc[i]);mi = min(mi,sumc[i]);}vector<int> p;for(int i = 1;i<=m;i++){if(sumc[i] == ma || sumc[i] == mi){for(int j = 1;j<=n;j++) p.push_back(a[j][i]),a[j][i] = 0;}}sort(p.begin(),p.end(),greater<int>());// for(int i = 0;i<p.size();i++) cout<<p[i]<<" ";// cout<<endl;// for(int i = 1;i<=n;i++){// for(int j = 1;j<=m;j++){// cout<<a[i][j]<<" ";// }// cout<<endl;// }int tot = -1;for(int i = 1;i<=n;i++){if(i&1){for(int j = 1;j<=m;j++){if(!a[i][j]) a[i][j] = p[++tot];}} else {for(int j = m;j;j--){if(!a[i][j]) a[i][j] = p[++tot];}}}
}void solve(){cin>>n>>m>>k;for(int i = 1;i<=n;i++){for(int j = 1;j<=m;j++){cin>>a[i][j];}}for(int i = 1;i<=k;i++) op();for(int i = 1;i<=n;i++){for(int j = 1;j<=m;j++){cout<<a[i][j]<<" ";}cout<<endl;}
}signed main(){// int T; cin>>T; while(T--)solve();return 0;
}