比赛链接:Codeforces Round 996 (Div. 2)
A-Two Frogs
思路:通过观察,考虑Alice的胜败与二者初始位置的距离有关,具体地,距离为偶数则Alice必胜,反之则败。
#include <bits/stdc++.h>
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define LL long long
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
int t, n, a, b;
int main()
{
IOS;
cin >> t;
while(t--)
{
cin >> n >> a >> b;
if((a-b)%2==0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
B-Crafting
思路:由于每合成一个材料,其他材料都将减少,我们不难发现,当有多个材料出现缺失时,无论如何都无法合成神器;当只有一个材料缺失时,如其他材料存在没有盈余的,也无法合成神器,如果都有盈余,只要缺失的数量小于等于盈余的最小值则必定能合成神器。另外,当没有材料缺失时,必定能合成神器。
#include <bits/stdc++.h>
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define LL long long
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
int t, n;
int main()
{
IOS;
cin >> t;
while (t--)
{
cin >> n;
vector<int> a(n + 1), b(n + 1);
rep(i, 1, n)
{
cin >> a[i];
}
rep(i, 1, n)
{
cin >> b[i];
}
int cnt = 0;
rep(i, 1, n)
{
if (b[i] - a[i] > 0)
cnt++;//记录有几个存在缺失的材料
}
if (cnt > 1)
{
cout << "NO" << endl;
}
else if (cnt == 0)
{
cout << "YES" << endl;
}
else if (cnt == 1)
{
int minnd = INT_MAX;
int pos = 0;
rep(i, 1, n)
{
if (b[i] - a[i] > 0)
pos = i;//记录这唯一一个存在缺失的材料
if (a[i] - b[i] >= 0)
minnd = min(minnd, a[i] - b[i]);//其他材料最小的盈余
}
if (b[pos] - a[pos] <= minnd)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}
C-The Trail
思路:根据题意,存在一个 x 满足 n*x=m*x,故使得 x 为 0 的方案必定正确。考虑到被篡改的路径只向右方或下方,即后操作的点不会影响之前的点,我们可以按照所给的方向字符串 s 逐个模拟:当方向为 D 时,修改该点,使其所在行总和为 0;当方向为 R 时,修改该点,使其所在列总和为 0;特殊地,对于终点 (n,m),我们根据最后的方向 s.back() 修改即可。记得开long long。
#include <bits/stdc++.h>
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define LL long long
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
int t, n, m;
LL a[1003][1003];
string s;
void op()
{
int x = 1, y = 1;
rep(i, 0, s.size() - 1)
{
LL sum = 0;
if (s[i] == 'D')
{
rep(j, 1, m)
sum += a[x][j];
a[x][y] = -sum;
x++;
}
else if (s[i] == 'R')
{
rep(j, 1, n)
sum += a[j][y];
a[x][y] = -sum;
y++;
}
}
LL finsum = 0;//处理最后一个点
if (s.back() == 'D')
{
rep(i, 1, m)
finsum += a[n][i];
a[n][m] = -finsum;
}
else if (s.back() == 'R')
{
rep(i, 1, n)
finsum += a[i][m];
a[n][m] = -finsum;
}
}
int main()
{
IOS;
cin >> t;
while (t--)
{
cin >> n >> m;
rep(i,1,n)
{
rep(j, 1, m)
a[i][j] = 0;
}
cin >> s;
rep(i, 1, n)
{
rep(j, 1, m)
cin >> a[i][j];
}
op();
rep(i, 1, n)
{
rep(j, 1, m)
cout << a[i][j] << " ";
cout << endl;
}
}
return 0;
}
1216

被折叠的 条评论
为什么被折叠?



