A. Tit for Tat
输入n,k和长度为n的数组,k代表进行操作的次数,每次操作任选两个数进行-1和+1,使得数组与原数组从前往后相比,在第一个不同数字的位置上,比原数组小,在操作次数限制的情况下,输出字典序最小的那种情况。
将数组从前至后,每个位置减至0,因为不能出现负数,并将+1操作放到最后一位上,输出数组。
来自 https://codeforces.com/contest/1516/problem/A
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<iterator>
using namespace std;
typedef long long ll;
template<class T>T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
#define setpre(a) cout<<fixed<<setprecision(a)
void solve() {
int n, k, sum = 0, step = 0;
int num[101] = { 0 };
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> num[i];
if (k > num[i]&&i<n-1) {
k -= num[i];
step += num[i];
num[i] = 0;
}
else if(i<n-1){
num[i] -= k;
step += k;
k = 0;
}
}
num[n - 1] += step;
for (int i = 0; i < n; i++) {
cout << num[i] << " ";
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
B. AGAGA XOOORRR
输入n和长度为n的数组,可以任意选择相邻两位数字进行异或运算,保留下一个结果数字,最后保留至少两位数字,且要求最后的所有数字相等。
进行异或运算,相同数字的结果为0,所以最后结果如果是偶数个数,那么将所有数字进行异或运算的结果就是0,如果是奇数个数,那么所有数字做完异或运算后的结果就是数组中保留下的相同数字,记录下出现这个数字的次数,若大于等于3次,则输出yes。
来自 https://codeforces.com/contest/1516/problem/B
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<iterator>
using namespace std;
typedef long long ll;
template<class T>T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
#define setpre(a) cout<<fixed<<setprecision(a)
#define FOR(i,n) for(int i=0;i<n;i++)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define bug cout<<"!!!\n";
void solve() {
ll n, m[2001] = { 0 }, s = 0;
cin >> n;
FOR(i, n) {
cin >> m[i];
s ^= m[i];
}
if (!s) {
yes;
}
else {
ll ss = 0, num = 0;
FOR(i, n) {
ss ^= m[i];
if (ss == s) {
num++;
ss = 0;
}
}
if (num >= 3) {
yes;
}
else {
no;
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}