AtCoder Beginning Contest 137

好久没打过abc了。

题目链接:https://atcoder.jp/contests/abc137/tasks_print


A:

水题。

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 int a, b;
21 
22 int main() {
23     cin >> a >> b;
24     cout << max(max(a + b, a - b), a * b) << endl;
25     return 0;
26 }
View Code

B:

一开始还看错题了。

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 const int lim = 1e6;
21 int k, x;
22 
23 int main() {
24     cin >> k >> x;
25     for (int i = x - k + 1; i <= x + k - 1; i++) {
26         if (i < -lim || i > lim) continue;
27         cout << i << " ";
28     }
29     puts("");
30     return 0;
31 }
View Code

C:

所有字符串自身sort一遍后再sort一遍,对于重复的字符串,ans+=C(重复个数,2)。

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 const int maxn = 1e5 + 10;
21 int n;
22 string s[maxn];
23 ll ans = 0;
24 
25 int main() {
26     scanf("%d", &n);
27     rep1(i, 1, n) {
28         cin >> s[i];
29         sort(s[i].begin(), s[i].end());
30     }
31     sort(s + 1, s + 1 + n);
32     int cnt = 1;
33     rep1(i, 2, n) {
34         if (s[i] == s[i - 1]) cnt++;
35         else {
36             ans += (ll)cnt * (cnt - 1) / 2;
37             cnt = 1;
38         }
39     }
40     ans += (ll)cnt * (cnt - 1) / 2;
41     printf("%lld\n", ans);
42     return 0;
43 }
View Code

D:

正向思考非常麻烦,不妨倒着枚举还剩多少天。用一个优先队列维护可做工作的最大收益即可。

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 const int maxn = 1e5 + 10;
21 // const int maxn = 5;
22 struct Job {
23     int earn, wait;
24     bool operator<(const Job &rhs)const {
25         if (wait != rhs.wait) return wait < rhs.wait;
26         else return earn > rhs.earn;
27     }
28 } a[maxn];
29 int n, m, tot = 0, p = 0;
30 ll ans = 0;
31 
32 int main() {
33     scanf("%d%d", &n, &m);
34     rep1(i, 1, n) {
35         int earn, wait; scanf("%d%d", &wait, &earn);
36         if (wait > m) continue;
37         a[++tot].wait = wait; a[tot].earn = earn;
38     }
39     int p = 0;
40     sort(a + 1, a + 1 + tot);
41     priority_queue<int>q;
42     while (!q.empty()) q.pop();
43     for (int reDay = 1; reDay <= m && p <= tot; reDay++) {
44         while (p < tot && a[p + 1].wait <= reDay) {
45             p++; q.push(a[p].earn);
46         }
47         if (!q.empty()) ans += (ll)q.top();
48         if (!q.empty()) q.pop();
49     }
50     printf("%lld\n", ans);
51     return 0;
52 }
View Code

猜你喜欢

转载自www.cnblogs.com/JHSeng/p/11336135.html