B
每个堆的石子最多操作a[i]-1次
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
std::ios_base::sync_with_stdio(false);
long long n;
cin >> n;
vector<long long> nums(n);
long long ans = 0;
for (int i = 0; i < n; i++)
{
cin >> nums[i];
ans += nums[i] - 1;
}
if (ans % 2 == 0)
cout << "sweet" << endl;
else
cout << "gui" << endl;
return 0;
}
C
模拟
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
using namespace std;
struct options
{
int op, z;
};
void printMatrix(const vector<vector<char>> &matrix)
{
for (const auto &row : matrix)
{
for (char c : row)
{
cout << c << ' ';
}
cout << endl;
}
cout << endl; // 空一行,方便观察
}
void rotateRow(vector<vector<char>> &matrix, int row)
{
char temp = matrix[row].back();
for (int i = matrix[row].size() - 1; i > 0; i--)
{
matrix[row][i] = matrix[row][i - 1];
}
matrix[row][0] = temp;
// printMatrix(matrix); // 打印旋转后的矩阵
}
void rotateCol(vector<vector<char>> &matrix, int col)
{
char temp = matrix.back()[col];
for (int i = matrix.size() - 1; i > 0; i--)
{
matrix[i][col] = matrix[i - 1][col];
}
matrix[0][col] = temp;
// printMatrix(matrix); // 打印旋转后的矩阵
}
int main()
{
std::ios_base::sync_with_stdio(false);
int n, m, x, y, p, q;
cin >> n >> m >> x >> y;
x--;
y--; // 将索引转换为0-based
vector<vector<char>> matrix(n, vector<char>(m));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> matrix[i][j];
}
}
cin >> p >> q;
vector<options> opts(p);
for (int i = 0; i < q; i++)
{
int op, z;
cin >> op >> z;
z--; // 将索引转换为0-based
opts[i] = {op, z};
}
for (int jk = 0; jk < p; jk++)
{
for (int i = 0; i < q; i++)
{
int op, z;
op = opts[i].op;
z = opts[i].z;
if (op == 1)
{
rotateRow(matrix, z);
}
else if (op == 2)
{
rotateCol(matrix, z);
}
}
}
cout << matrix[x][y] << endl;
return 0;
}
D
将这题看成看成一些积木块的堆积,进行的操作就是可以将任意一个积木块移动到任意的位置,也就是说,一共有sum个积木块的话,这个操作保证可以摆出所有的排列方式。
要求所有元素的最大公因数,设其为x,那么x一定也是sum的因数,那么sum的所有因数都可能被排列出来成为最小的那堆,或者是其更小的组成部分,那么只要满足\(x<=sum/n\)就是一个符合题意的方案,因此只需要对sum进行因数分解,然后筛选符合\(x<=sum/n\)的因数就可以了
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<long long> get_divisors(long long n)
{
vector<long long> res;
for (int i = 1; i <= n / i; i++) // i<=n/i绝对不会溢出
{
if (n % i == 0)
{
res.push_back(i);
if (i != n / i)
{
res.push_back(n / i);
}
}
}
sort(res.begin(), res.end());
return res;
}
int main()
{
int n;
cin >> n;
vector<int> a(n);
long long sum = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
sum += a[i];
}
auto yinzi = get_divisors(sum);
long long ans = 0;
for (int i = 0; i < yinzi.size(); i++)
{
if (yinzi[i] <= sum / n)
{
ans++;
}
}
if (n == 1)
cout << 1 << endl;
else
cout << ans << endl;
return 0;
}
标签:第四场,matrix,int,多校,long,vector,补题,include,op
From: https://www.cnblogs.com/z4t15/p/18141690