A题:
因此,令y = x - 1 为最优。
ac代码:
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 2e6 + 5;
ll t,x;
void solve() {
cin>>t;
while(t--){
cin>>x;
cout<<x-1<<endl;
}
}
int main() {
ios;
solve();
return 0;
}
B题:双指针遍历即可。
ac代码:
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e5 + 5;
string a,b;
int t,n,m;
void solve() {
cin>>t;
while(t --) {
int i = 0,j = 0,ans = 0;
cin>>n>>m>>a>>b;
while(j < m) {
if(a[i] != b[j]) j ++;
else {
ans ++;
i ++;
j ++;
}
}
cout<<ans<<endl;
}
}
int main() {
ios;
solve();
return 0;
}
C题:a1取大点,直接加就行,不会超出题目范围,当时没看出来,所以我用不等式控制了一下大小。
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e5 + 5;
int t,n,x[N];
void solve() {
cin>>t;
while(t --) {
int last;
cin>>n;
for(int i = 2; i <= n; i ++) {
cin>>x[i];
}
last = x[2] + 1;
cout<<last;
for(int i = 2; i <= n; i ++) {
int k = (x[i + 1] - x[i]) / last + 1;
last = last * k + x[i];
cout<<" "<<last;
}
cout<<endl;
}
}
int main() {
ios;
solve();
return 0;
}
D题:
对于每名选手的最大可能获得分数,我们只要要在min(n,k)回合中找即可(证明略)。
让我们定义 𝑠𝑢𝑚𝑖 和 𝑝𝑜𝑠𝑖 :
- 在前 𝑖 个回合中出现的位置的数值总和。
- 如果棋手决定移动 𝑖 次,他将在哪个位置停止。
ac代码:
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 2e6 + 5;
ll t,n,k,pb,ps,p[N],a[N];
bool vst[N];
ll getsc(int s) {
ll sum = 0,mx = 0,r = k;
memset(vst,0,sizeof(vst));
while(!vst[s] && r > 0) {
vst[s] = 1;
mx = max(mx,sum + r * a[s]);
r --;
sum += a[s];
s = p[s];
}
return mx;
}
void solve() {
cin>>t;
while(t--){
cin>>n>>k>>pb>>ps;
for(int i = 1; i <= n; i ++) cin>>p[i];
for(int i = 1; i <= n; i ++) cin>>a[i];
ll B = getsc(pb),S = getsc(ps);
if(B > S) cout<<"Bodya"<<endl;
else if(B == S) cout<<"Draw"<<endl;
else cout<<"Sasha"<<endl;
}
}
int main() {
ios;
solve();
return 0;
}
E题:
在主对角线上放置 𝑛−2 个单元格。然后在 (𝑛−1,𝑛) 和(𝑛,𝑛) 处放置两个单元格,通过这种方法,我们可以生成所有可能的曼哈顿距离。奇数距离产生于主对角线上的单元格和 (𝑛−1,𝑛) 之间。偶数距离产生于主对角线上的单元格与 (𝑛,𝑛) 之间。
ac代码:
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 2e6 + 5;
ll t,n;
void solve() {
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n-2;i++){
cout<<i<<" "<<i<<endl;
}
cout<<n-1<<" "<<n<<endl<<n<<' '<<n<<endl;
}
}
int main() {
ios;
solve();
return 0;
}
F题:
F题貌似是异或前缀和加二分,没做。