9710

2个月前
#include <iostream>
#include <cstring>

using namespace std;

const int N = 110;

int cnt[N];

int mex() {
for (int i = 0; i < N; ++i) {
if (cnt[i] == 0) {
return i;
} else {
--cnt[i];
}
}
return 0;
}

int main() {
int T, n, x;
cin >> T;
while (T--) {
cin >> n;
memset(cnt, 0, sizeof cnt);
for (int i = 0; i < n; ++i) {
cin >> x;
++cnt[x];
}
cout << mex() + mex() << endl;
}

return 0;
}


2个月前
#include <iostream>

using namespace std;

const int N = 110;

int a[3][N], b[N];

int main() {
int T, n;
cin >> T;
while (T--) {
cin >> n;

for (int i = 0; i < 3; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}

b[0] = a[0][0];
for (int i = 1; i < n - 1; ++i) {
for (int j = 0; j < 3; ++j) {
if (a[j][i] != b[i - 1]) {
b[i] = a[j][i];
}
}
}

for (int i = 0; i < 3; ++i) {
if (a[i][n - 1] != b[0] && a[i][n - 1] != b[n - 2]) {
b[n - 1] = a[i][n - 1];
}
}

for (int i = 0; i < n; ++i) {
cout << b[i] << " ";
}
cout << endl;
}

return 0;
}


2个月前
#include <iostream>

using namespace std;

int main(){
int T, n, a, b;
cin >> T;

while (T--){
cin >> n;
while (n--) {
if (n % 2) {
cin >> a;
} else {
cin >> b;
}
if (n % 2 == 0) {
cout << -b << " " << a << " ";
}
}
cout << endl;
}

return 0;
}


2个月前
#include <iostream>

using namespace std;

int main() {
int T;
cin >> T;
int n, k;
string s;
for (int i = 1; i <= T; ++i) {
cin >> n >> k >> s;
int cnt = 0;
for (int i = 0, j = n - 1; i < j; ++i, --j) {
if (s[i] != s[j]) {
++cnt;
}
}
cout << "Case #"<< i << ": " << abs(cnt - k) << endl;
}

return 0;
}


3个月前
#include <iostream>
#include <string>

using namespace std;

string dfs(int n) {
string res;
for (int i = 14; ~i; --i) {
if (n >> i & 1) {
if (res.size()) {
res += '+';
}

if (i == 0) {
res += "2(0)";
} else if (i == 1) {
res += '2';
} else {
res += "2(" + dfs(i) + ')';
}
}
}
return res;
}

int main() {
int n;
while (cin >> n) {
cout << dfs(n) << endl;
}

return 0;
}


3个月前
#include <iostream>

using namespace std;

int main() {
int T, n, x;
cin >> T;

while (T--) {
cin >> n;

int last = -1;
int res = 0;
for (int i = 0; i < n; ++i) {
cin >> x;
if (x) {
if (last >= 0) {
res += i - last - 1;
}
last = i;
}
}
cout << res << endl;
}

return 0;
}


3个月前
#include <iostream>
#include <unordered_set>

using namespace std;

int f[10];
unordered_set<int> S;

int main() {
f[0] = 1;
for (int i = 1; i < 10; ++i) {
f[i] = f[i - 1] * i;
}

for (int i = 1; i < 1 << 10; ++i) {
int s = 0;
for (int j = 0; j < 10; ++j) {
if (i >> j & 1)
s += f[j];
}
S.insert(s);
}

int n;
while (cin >> n, n >= 0)
if (S.count(n)){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}


3个月前
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 1000010;

int idx[N], q[N];
int n;

int main() {
scanf("%d", &n);
int x;

memset(idx, -1, sizeof idx);
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
idx[x] = i;
}

int t = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
int k = idx[x];

if (k == -1) {
continue;
}

int l = 0;
int r = t;
while (l < r) {
int mid = l + r + 1 >> 1;
if (q[mid] < k) {
l = mid;
} else {
r = mid - 1;
}
}

q[r + 1] = k;
t = max(t, r + 1);
}

printf("%d\n", t);

return 0;
}


3个月前
#include <iostream>

using namespace std;

const int N = 100010;

int a[N], b[N];

int main() {
int n, m, l, r, c;
cin >> n >> m;

for (int i = 1; i <= n; ++i) {
cin >> a[i];
b[i] = a[i] - a[i - 1];
}

while (m--) {
cin >> l >> r >> c;
b[l] += c;
b[r + 1] -= c;
}

for (int i = 1; i <= n; ++i) {
a[i] = a[i - 1] + b[i];
cout << a[i] << ' ';
}

cout << endl;

return 0;
}


4个月前
#include <iostream>

using namespace std;

const int N = 2e5 + 10;

int w[N];
int p[N];
int cnt[N];

int T, n;

int find(int x) {
if (p[x] != x) {
p[x] = find(p[x]);
}

return p[x];
}

int main() {
cin >> T;
while (T--) {
cin >> n;

for (int i = 1; i <= n; ++i) {
cin >> w[i];
p[i] = i;
cnt[i] = 1;
}

for (int i = 1; i <= n ; ++i) {
if (w[i] == i) {
continue;
}

int pa = find(i);
int pb = find(w[i]);

if (pa != pb) {
cnt[pb] += cnt[pa];
p[pa] = pb;
}
}

for (int i = 1; i <= n; ++i) {
cout << cnt[find(i)] << ' ';
}
cout << endl;
}

return 0;
}