Atcoder Beginner 094 A B C D 题解

< A >

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int a, b, c;

int main() {
while(~scanf("%d %d %d", &a, &b, &c)) {
if(b >= c - a && c >= a) puts("YES");
else puts("NO");
}
return 0;

}

< B >

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n, m, x;
int a[120];
int t[120];

int main() {
while(~scanf("%d %d %d", &n, &m, &x)) {
memset(t, 0, sizeof(t));
for(int i = 0; i < m; i++) scanf("%d", &a[i]);
for(int i = 0; i < n; i++) t[a[i]] = 1;
int c1 = 0, c2 = 0;
for(int i = x; i < n; i++) {
if(t[i] == 1) c1++;
}
for(int i = x; i > 0; i--) {
if(t[i] == 1) c2++;
}
printf("%d\n", min(c1, c2));
}
return 0;

}

< C >

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int Maxx = 2e5 + 7;
const int Inf = 1e9 + 7;
int n;
int a[Maxx];
int t[Maxx];

int main() {
while(~scanf("%d", &n)) {
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = 1; i <= n; i++) t[i] = a[i];
sort(a + 1, a + n + 1);
int p1 = a[n / 2], p2 = a[n / 2 + 1];
for(int i = 1; i <= n; i++) {
if(t[i] <= p1) printf("%d\n", p2);
else if(t[i] >= p2) printf("%d\n", p1);
}
}
return 0;

}

< D >

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int Maxx = 1e5 + 7;
const int Inf = 1e9 + 7;
int n;
int a[Maxx];

int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
int t = a[n] / 2;
int min = Inf;
int p;
for(int i = 1; i <= n; i++) {
if(abs(a[i] - t) <= min) {
min = abs(a[i] - t);
p = a[i];
}
}
if(n == 2) printf("%d %d\n", a[2], a[1]);
else printf("%d %d\n", a[n], p);
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120