A题
链接:https://codeforces.com/contest/2055/problem/a
题意:两个人Alice和Bob初始位置分别位a,b,n为长度大小,Alice先手选择一个方向前进,两人位置不重叠且一次走一格,谁不能走谁输
解题思路:看他们两个谁先不能朝着对方位置前进,即为输
void smoking() { int n, a, b; cin >> n >> a >> b; if (abs(a - b) & 1) cout << "NO\n"; else cout << "YES\n"; }
B题
链接:https://codeforces.com/contest/2055/problem/b
题意:有n种材料,第i种有a[i]个,如果第i种不够,可以a[i] ++,然后除第i种以外每种 - 1,问最终可不可以符合要求
解题思路:如果a[i] < b[i],那么就记录他们的差值c[i],并记录总和tmp,最后将a[i]变为a[i]和b[i]中较大的数,再令a[i] 加上除它本身外的tmp,即a[i] += tmp - c[i];如果a[i] < b[i]则说明肯定不符合要求
样例 4 0 5 5 1 1 4 4 0 那么 c:-1 0 0 0 tmp -1 那么更新后的a a[1] = -1 - (-1) + 1 a[2] = -1 - 0 + 5 a[3] = -1 - 0 + 5 a[4] = -1 - 0 + 1
void smoking() { int n; cin >> n; vector<int> a(n + 1), b(n + 1), c(n + 1); for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> b[i]; int tmp = 0; for (int i = 1; i <= n; ++i) { if (a[i] < b[i]) { c[i] = a[i] - b[i]; tmp += c[i]; } } for (int i = 1; i <= n; ++i) { a[i] = tmp - c[i] + (a[i] > b[i] ? a[i] : b[i]); // cout << a[i] << ' ' << b[i] << '\n'; if (a[i] < b[i]) { cout << "NO\n"; return; } } cout << "YES\n"; }
C题
链接:https://codeforces.com/contest/2055/problem/C
题意:给n行m列数,一串字符s(仅包含D和R且length <= n + m - 2),D代表向下,R代表向上,从(1,1)开始,给途径的数赋值(初始为0),求最终令每行每列都相等的数组
解题思路:没指定必须等于的数,那么就令x = 0,那么问题就变成了在路径中,将接下来没改变的数的和的倒数赋值给当前数,例如
3 3 DRRD 0 2 3 0 0 0 3 1 0 那么从(1,1)开始,下一步是D,则不确定下数,即向右查看,遍历一行,a[1][1] -= sum;即a[1][1] = -5 那么(2, 1),则是遍历一列,即a[2][1] = 2; 以此类推
void smoking() { int n, m; cin >> n >> m; string s; cin >> s; vector<vector<int>> a(n + 1, vector<int>(m + 1)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) cin >> a[i][j]; } int i = 1, j = 1; while (i + j <= n + m) { if (s[i + j - 2] == 'D' || i + j == n + m) { int res = 0; for (int x = 1; x <= m; ++x) { res -= a[i][x]; } a[i][j] = res; i++; } else { int res = 0; for (int x = 1; x <= n; ++x) { res -= a[x][j]; } a[i][j] = res; j++; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cout << a[i][j] << " \n"[j == m]; } } }标签:tmp,996,题意,int,void,Codeforces,cin,vector,Div From: https://blog.csdn.net/2301_80078630/article/details/145125887