A-SW的与众不同数组_2022学年第一学期郑州大学ACM招新赛&选拔赛 (nowcoder.com)
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
int n;cin >> n;
vector<int> v;
for(int i = 1; i <= n; i++){
int x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
cout << ((n - v.size()) % 2 == 0 ? v.size() : v.size() - 1);
cout << '\n';
}
signed main(){
int t = 1;cin >> t;
while(t--)solve();
return 0;
}
B-WASD机器人_2022学年第一学期郑州大学ACM招新赛&选拔赛 (nowcoder.com)
//暴力枚举
#include <bits/stdc++.h>
using namespace std;
signed main(){
string s; cin >> s;
int n = s.size();
int x, y; cin >> x >> y;
if(abs(x) + abs(y) > s.size()){cout<<-1;return 0;}
// 现有的 l, r, u, d 的数量
int nl = 0, nr = 0, nu = 0, nd = 0;
for(auto c : s){
nl += (c == 'L');
nr += (c == 'R');
nu += (c == 'U');
nd += (c == 'D');
}
int res = n;
// 枚举最后结果中 l, r 数量 此时 u, d 数量也确定了
int l, r, u, d;
// abs(l-r)==x x>0的话r-l==x
for(int i = 0; i <= n; i ++){
if(x > 0) l = i, r = x + i;
else l = -x + i, r = i;
int dt = (n - l - r - y) / 2;//n-l-r表示的是
if(y > 0) u = y + dt, d = dt;
else u = dt, d = -y + dt;
if(l < 0 || r < 0 || d < 0 || u < 0 ) break;
int sum = abs(nl - l) + abs(nr - r) + abs(nu - u) + abs(nd - d);
res = min(res, (sum%2==0?sum/2:sum/2+1));
}
cout << res << '\n';
}
D-SW的七星光芒剑_2022学年第一学期郑州大学ACM招新赛&选拔赛 (nowcoder.com)
#include <bits/stdc++.h>
using namespace std;
char g[1010][1010];
//找规律 找六个点
//注意斜线怎么画出来 是用i j两个变量进行偏移
signed main()
{
int n; cin >> n;
memset(g, ' ', sizeof g);
for(int i = 1; i <= 6 * n - 5; i ++) if(i & 1) g[n][i] = g[3 * n - 2][i] = '*';
for(int i = 1, j = 3 * n - 2; i <= 3 * n - 2; i ++, j --) g[i][j] = '*';
for(int i = 1, j = 3 * n - 2; i <= 3 * n - 2; i ++, j ++) g[i][j] = '*';
for(int i = 4 * n - 3, j = 3 * n - 2; i >= n; i --, j --) g[i][j] = '*';
for(int i = 4 * n - 3, j = 3 * n - 2; i >= n; i --, j ++) g[i][j] = '*';
for(int i = 1; i <= 4 * n - 3; i ++){
for(int j = 1; j <= 6 * n - 5; j ++)
cout << g[i][j];
cout << '\n';
}
}
H-旋转数组_2022学年第一学期郑州大学ACM招新赛&选拔赛 (nowcoder.com)
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
// vector<vector<int>> a;
map<int,int> dp[N];//dp[i][j]表示 以i列结尾,且数值为j的最长字串长度
// dp[j+1][x]=max(dp[j+1][x],dp[j][x−1]+1)
int n, m;
int res = 0;
signed main(){
cin >> n >> m;
// a = vector<vector<int>> (n, vector<int>(m));
int a[n][m];
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
cin >> a[i][j];
for(int j = 0; j < m; j ++)
for(int i = 0; i < n; i ++)
{
int x = a[i][j];
dp[j + 1][x] = max(dp[j + 1][x], dp[j][x - 1] + 1);
//等于前j列 以x-1结尾的字串长度+1
res = max(res, dp[j + 1][x]);//更新
}
cout << res << '\n';
}
G-凑数字_2022学年第一学期郑州大学ACM招新赛&选拔赛 (nowcoder.com)
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e3+6;
int a[N];
//凑出来0 然后用[1+(n-1)]*n获得n^2 n^2+0=n^2
void solve(){
int n;
cin >> n;
if(n==2){ cout<<-1;return ;}
if(n==3){
cout<<"1 + 2\n3 * 3";
return ;
}
if(n==4){
cout<<"1 + 3\n4 + 4\n2 * 8";
return;
}
if(n==5){
cout<<"1 * 2\n2 + 3\n4 * 5\n20 + 5";
return ;
}
if(n==6){
cout<<"5 - 4\n1 - 1\n2 * 3\n6 * 6\n36 + 0";
return ;
}
for(int i=1;i<=n;i++)a[i]=i;
cout<<"2 + 3\n";
cout<<"5 - 5\n";
cout<<"0 * 4\n";
cout<<"1 + "<<n-1<<'\n';
for(int i=6;i<=n-2;i++)cout<<a[i]<<" * 0\n";
cout<<n<<" * "<<n<<'\n';
cout<<"0 + "<<n*n;
}
signed main(){
int t = 1;
while(t--) {
solve();
}
return 0;
}
J-SW玩扫雷_2022学年第一学期郑州大学ACM招新赛&选拔赛 (nowcoder.com)
#include <bits/stdc++.h>
using namespace std;
const int N=106;
char a[N][N];
char b[N][N];
int main(){ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,m;cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='*') cout << a[i][j];
else {
int cnt=0;
for(int k=max(1,i-1);k<=min(n,i+1);k++){//左取max(1,i-1) 右取min(n,i+1)
for(int q=max(1,j-1);q<=min(m,j+1);q++){
if(k==i&&q==j) continue;
if(a[k][q]=='*') cnt++;
}
}
cout << cnt ;
}
}
cout << '\n';
}
return 0;
}