传送门
A Number Transformation
赛时做复杂了,其实就是两种情况,x大于y或者x不能整除y的情况下不行,能整出的情况下直接输出1和x/y即可写复杂了,得亏数据范围小不然感觉容易挂
//
// Author : north_h
// File : A.cpp
// Time : 2023/7/18/12:56
//
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define endl '\n'
const int N = 10010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;
using namespace std;
void solve() {
int x, y;
cin >> x >> y;
if (y % x != 0 || x > y)cout << "0 0" << endl;
else if (x == y)cout << "1 1" << endl;
else {
int xx = y / x;
for (int i = 2; i <= xx; i++) {
int sum = 1;
int b = 0;
while (sum < xx)sum *= i, b++;
if (sum == xx) {
cout << b << ' ' << i << endl;
return;
}
}
}
}
int main() {
IOS;
int h_h = 1;
cin >> h_h;
while (h_h--)solve();
return 0;
}
B Dictionary
直接根据给出的形式计算即可,可以直接不思考预处理出来直接查询
//
// Author : north_h
// File : B.cpp
// Time : 2023/7/18/13:12
//
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define endl '\n'
const int N = 10010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;
using namespace std;
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int cnt = (int) (s[0] - 'a') * 25 + s[1] - 'a' + 1;
if (s[1] > s[0])cnt--;
cout << cnt << endl;
}
}
int main() {
IOS;
int h_h = 1;
//cin >> h_h;
while (h_h--)solve();
return 0;
}
C Infinite Replacement
这个题真的时排列组合的数量都忘了,还自己一个一个去数,直接就是2 的次方,一个秒了的
//
// Author : north_h
// File : C.cpp
// Time : 2023/7/18/13:32
//
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define endl '\n'
const int N = 10010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;
using namespace std;
void solve() {
string a, b;
cin >> a >> b;
bool ok = false;
for (auto i: b)if (i == 'a')ok = true;
if (ok && b.size() == 1)cout << 1 << endl;
else if (ok && b.size())cout << -1 << endl;
else cout << (1ll << a.size()) << endl;
}
int main() {
IOS;
int h_h = 1;
cin >> h_h;
while (h_h--)solve();
return 0;
}
D A-B-C Sort
可以发现两种操作以后只是改变一对一对相邻的位置关系,奇数时第一个不参与偶数时从第一个开始,后面的一对一对的排序,最后判断是否是非递减的即可,直接写挂了,难受
//
// Author : north_h
// File : D.cpp
// Time : 2023/7/18/14:45
//
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se seco1nd
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define endl '\n'
const int N = 10010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for(auto &i:a)cin >>i;
int last = 0;
if (n % 2 != 0)last = a[0];
//cout<<last<<endl;
for (int i = (n % 2 != 0); i < n; i += 2) {
if (min(a[i], a[i + 1]) >= last)last = max(a[i], a[i + 1]);
else {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
int main() {
IOS;
int h_h = 1;
cin >> h_h;
while (h_h--)solve();
return 0;
}
F Desktop Rearrangement
主要还是读懂题意,读懂题意以后就是动态的前缀和,单点修改区间查询,所以可以使用树状数组来做,可以用二维的树状数组来做,因为这道题的原因,也可以吧坐标映射到一维上,用一维的树状数组来做
//
// Author : north_h
// File : E.cpp
// Time : 2023/7/18/19:06
// _ _ _
// _ __ ___ _ __| |_| |__ | |__
//| '_ \ / _ \| '__| __| '_ \ | '_ \
//| | | | (_) | | | |_| | | | | | | |
//|_| |_|\___/|_| \__|_| |_|___|_| |_|
// |_____|
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a, b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define endl '\n'
const int N = 1010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;
using namespace std;
int tr[N][N];
char g[N][N];
int n, m, q;
inline int lowbit(int x) {
return x & (-x);
}
void add(int x,int y,int k) {
for (int i = x; i <= n; i += lowbit(i)) {
for (int j = y; j <= m; j += lowbit(j)) {
tr[i][j] += k;
}
}
}
int query(int x,int y) {
int res = 0;
for (int i = x; i; i -= lowbit(i)) {
for (int j = y; j; j -= lowbit(j)) {
res += tr[i][j];
}
}
return res;
}
int query(int x1,int y1,int x2,int y2){
return query(x2,y2)-query(x2,y1-1)-query(x1-1,y2)+query(x1-1,y1-1);
}
void solve() {
cin >> n >> m >> q;
int sum = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> g[i][j];
if (g[i][j] == '*') {
sum++;
add(i, j, 1);
}
}
}
while (q--) {
int x, y;
cin >> x >> y;
if (g[x][y] == '*') {
sum--;
g[x][y] = '.';
add(x, y, -1);
} else {
sum++;
g[x][y] = '*';
add(x, y, 1);
}
int col = sum / n;
int cnt = sum % n;
int t = 0;
if (col)t += query(1, 1, n, col);
if (cnt)t += query(1, col + 1, cnt, col + 1);
cout << sum - t << endl;
}
}
int main() {
IOS;
int h_h = 1;
//cin >> h_h;
while (h_h--)solve();
return 0;
}