少女祈祷中...

[Dashboard - Codeforces Round 980 (Div. 2) - Codeforces)

A. Profitable Interest Rate

思路:a - x >= b - 2x, 变形一下得 2 * a - b, 最小为0 最大为a 即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;


void solve() {
ll a, b;
cin >> a >> b;
ll t = 2 * a - b;
cout << min(a, max((ll)0, t)) << endl;;
}

int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}

B. Buying Lemonade

思路:一遍一遍的取,每次遍历取一个,然后为0,就白按一次,然后下次遍历就不按这个。

转换一下,先排个序,遍历就可,细节处理见代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;

void solve() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
ll ans = k, pre = 0;
for(int i = 0; i < n && k > 0; i++) {
k -= (a[i] - pre) * (n - i);
pre = a[i];
if(k > 0) ans++;
else break;
}
cout << ans << endl;
}

int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}

C. Concatenation of Arrays

思路:呃 是个贪心,大概猜一猜感觉是先按照较小值排序,较小值相同,按较大值排序。 证明的话(呃还是猜吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;


void solve() {
int n;
cin >> n;
vector<pii> a(n);
for(int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
a[i] = {l, r};
}
sort(a.begin(), a.end(), [&](auto a, auto b) {
int mna = min(a.first, a.second);
int mxa = max(a.first, a.second);
int mnb = min(b.first, b.second);
int mxb = max(b.first, b.second);
if(mna == mnb) {
return mxa < mxb;
}
return mna < mnb;
});
for(auto i : a) {
cout << i.first << ' ' << i.second << ' ';
}
cout << '\n';
}

int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}

有能力了再来做D吧(

谢谢观看