AtCoder Beginner Contest 092
A - Traveling Budget
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
int a, b, c, d;
int main(){
cin >> a >> b >> c >> d;
cout << min(a, b) + min(c, d) << endl;
return 0;
}
B - Chocolate
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
int n, x, d;
int main() {
cin >> n >> d >> x;
int res = x;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
res++;
for (int j = 2; j <= d; j++) {
if ((j - 1) % a == 0) res++;
}
}
cout << res << endl;
return 0;
}
C - Traveling Plan
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
int n, a[N], sum = 0;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += abs(a[i] - a[i - 1]);
}
sum += abs(a[n]);
for (int i = 1; i <= n; i++) {
cout << sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +abs(a[i+1]-a[i-1])<< endl;
}
cout << endl;
return 0;
}
D - Grid Components
给出两个数a和b,要求构造一个地图,使得#联通块的数量为a,.联通块的数量为b
a,b<=500,地图大小小于100x100
构造出一个很大的固定长100 宽100的矩形来完成它,可以将\(100*100\)分为2个\(50*100\) 一个为黑色背景 一个为白色背景,然后往上放
不同的颜色即可
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
a--, b--;
printf("100 100\n");
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 100; j++) {
if (i % 2 && j % 2 && a) {
a--;
printf(".");
} else
printf("#");
}
printf("\n");
}
for (int i = 50; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (i % 2 && j % 2 && b) {
b--;
printf("#");
} else
printf(".");
}
printf("\n");
}
return 0;
}