[AGC001A] BBQ Easy
为了让最小的值不影响更大的值,只搭配次小的。
#include <bits/stdc++.h>
#define d(x) cerr << #x << " => " << x << endl
#define D cerr << "Passed [" << __FUNCTION__ << "] on line " << __LINE__ << endl
#define dd(x) cerr << #x << endl
#define ms(x) memset(x, 0, sizeof x)
using namespace std;
int rd() {
int f = 1, val = 0; char ch = getchar();
while(!isdigit(ch)) f = (ch == '-' ? -1 : 1), ch = getchar();
while(isdigit(ch)) val = val * 10 + ch - '0', ch = getchar();
return f * val;
}
const int N = 1e5 + 5;
int a[N];
signed main() {
int n = rd();
for(int i = 1; i <= 2 * n; i++) a[i] = rd();
sort(a + 1, a + 2 * n + 1);
int ans = 0;
for(int i = 1; i <= 2 * n; i += 2) ans += a[i];
cout << ans << endl;
return 0;
}
[AGC001B] Mysterious Light
递归,除前两步操作外,本质是遍历一个循环的平行四边形。
#include <bits/stdc++.h>
#define d(x) cerr << #x << " => " << x << endl
#define D cerr << "Passed [" << __FUNCTION__ << "] on line " << __LINE__ << endl
#define dd(x) cerr << #x << endl
#define ms(x) memset(x, 0, sizeof x)
#define int long long
using namespace std;
int rd() {
int f = 1, val = 0; char ch = getchar();
while(!isdigit(ch)) f = (ch == '-' ? -1 : 1), ch = getchar();
while(isdigit(ch)) val = val * 10 + ch - '0', ch = getchar();
return f * val;
}
int solve(int a, int b) {
if(b == 0) return 0;
if(a < b) return solve(b, a);
if(a % b == 0) return 2 * (a - a % b) - b;
return 2 * (a - a % b) + solve(b, a % b);
}
signed main() {
int n = rd(), x = rd();
cout << n + solve(x, n - x) << endl;
return 0;
}
[AGC002A] 过水
[AGC002C] Knot Puzzle
如果有相邻的两段绳子比
#include <bits/stdc++.h>
#define d(x) cerr << #x << " => " << x << endl
#define D cerr << "Passed [" << __FUNCTION__ << "] on line " << __LINE__ << endl
#define dd(x) cerr << #x << endl
#define ms(x) memset(x, 0, sizeof x)
using namespace std;
int rd() {
int f = 1, val = 0; char ch = getchar();
while(!isdigit(ch)) f = (ch == '-' ? -1 : 1), ch = getchar();
while(isdigit(ch)) val = val * 10 + ch - '0', ch = getchar();
return f * val;
}
const int N = 1e5 + 5;
int a[N];
void solve() {
int n = rd(), L = rd();
for(int i = 1; i <= n; i++) {
a[i] = rd();
}
int flag = true;
for(int i = 2; i <= n; i++) {
if(a[i - 1] + a[i] >= L) {
puts("Possible");
for(int j = 1; j < i - 1; j++) {
printf("%d\n", j);
}
for(int j = n - 1; j >= i; j--) {
printf("%d\n", j);
}
printf("%d\n", i - 1);
flag = false;
break;
}
}
if(flag) {
puts("Impossible");
}
}
signed main() {
int T = 1;
while(T--) solve();
return 0;
}
此处评论已关闭