C. Coin Rows
Alice 和 Bob 在一个
2
×
m
2 \times m
2×m 的矩形上玩游戏,矩形的每一个格子上都有一个数
a
i
,
j
a_{i,j}
ai,j
Alice 和 Bob 一开始站在左上角格子 (1,1) 上,每个人都只能向下或者向右移动,直到移动到终点 (2,m) 上,经过一个格子时会取走格子上的数,赢得相应的得分
Alice 首先开始移动,Bob 不能取走 Alice 已经取走的数
Alice 期望最小化 Bob 的得分,Bob 则希望最大化自己的得分
请输出 Bob 的最大得分
思路:
枚举每一列作为Alice向下走的那一步,那么Bob的得分只能是右上角和左下角Alice并未走过的分数,对每个Alice向下走的
i
i
i ,求出Bob两种方式
m
a
x
max
max,再对所有
m
a
x
max
max求
m
i
n
min
min
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=1e5+10;
int a[3][N];
int s[3][N];
void solve()
{
cin>>n;
for(int i=1;i<=2;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
for(int i=1;i<=2;i++)
{
for(int j=1;j<=n;j++)
{
s[i][j]=s[i][j-1]+a[i][j];
}
}
int res=ll_INF;
for(int i=1;i<=n;i++)
{
int maxv=max(s[1][n]-s[1][i],s[2][i-1]);
res=min(res,maxv);
}
cout<<res<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}
D. Co-growing Sequence
题目描述:
思路:
字典序最小,那么
b
1
=
0
b_1=0
b1=0,对于一个满足题意的数组,二进制下所有
a
i
−
1
X
O
R
b
i
−
1
a_{i-1}XORb_{i-1}
ai−1XORbi−1中的
1
1
1 ,
a
i
X
O
R
b
i
a_{i}XORb_{i}
aiXORbi也得有,那么
b
i
b_i
bi就是把没有补齐的
1
1
1补齐
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=2e5+10;
int a[N];
int b[N];
void solve()
{
cin>>n;
int now;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=2;i<=n;i++)
{
int t=a[i];
now=a[i]|a[i-1];
b[i]=now-t;
a[i]^=b[i];
}
for(int i=1;i<=n;i++)cout<<b[i]<<' ';
cout<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)
solve();
return 0;
}