A - Points in Segments
题意:implement
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool vis[105];
int ans[105], atop;
void test_case() {
int n, m;
scanf("%d%d", &n, &m);
while(n--) {
int u, v;
scanf("%d%d", &u, &v);
for(int i = u; i <= v; ++i)
vis[i] = 1;
}
for(int i = 1; i <= m; ++i)
if(!vis[i])
ans[++atop] = i;
printf("%d\n", atop);
for(int i = 1; i <= atop; ++i)
printf("%d%c", ans[i], " \n"[i == atop]);
if(atop == 0)
puts("");
}
int main() {
#ifdef KisekiPurin
freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
int t = 1;
for(int ti = 1; ti <= t; ++ti) {
//printf("Case #%d: ", ti);
test_case();
}
}
B - Obtaining the String
题意:给两个字符串s,t,使用冒泡排序从s到达t,求方法。
题解:implement
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[105], ss[105], t[105], tt[105];
int ans[10005], atop;
void test_case() {
int n;
scanf("%d%s%s", &n, s + 1, t + 1);
strcpy(ss + 1, s + 1);
strcpy(tt + 1, t + 1);
sort(ss + 1, ss + 1 + n);
sort(tt + 1, tt + 1 + n);
if(strcmp(ss + 1, tt + 1) != 0) {
puts("-1");
return;
}
for(int i = 1; i <= n; ++i) {
while(t[i] != s[i]) {
for(int j = i + 1; j <= n; ++j) {
if(s[j] == t[i]) {
int k = j - 1;
while(t[i] != s[i]) {
ans[++atop] = k;
swap(s[k], s[k + 1]);
--k;
}
break;
}
}
}
}
printf("%d\n", atop);
for(int i = 1; i <= atop; ++i)
printf("%d%c", ans[i], " \n"[i == atop]);
}
int main() {
#ifdef KisekiPurin
freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
int t = 1;
for(int ti = 1; ti <= t; ++ti) {
//printf("Case #%d: ", ti);
test_case();
}
}