Educational Codeforces Round 62

时间:2022-06-06 13:52:51

A. Detective Book

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e4 + ;
int N;
int a[maxn];
int maxx = ; int main() {
scanf("%d", &N);
for(int i = ; i < N; i ++)
scanf("%d", &a[i]); int ans = ;
for(int i = ; i < N; i ++) {
maxx = max(a[i], maxx);
if(maxx == i + ) ans ++;
} printf("%d\n", ans);
return ;
}

B. Good String

代码:

#include <bits/stdc++.h>
using namespace std; int T, N;
string s; int main() {
scanf("%d", &T);
while(T --) {
scanf("%d", &N);
cin >> s;
int st, en;
if(s[] == '>')
printf("0\n");
else if(s[N - ] == '<')
printf("0\n");
else {
for(int i = ; i < N; i ++) {
if(s[i] == '>') {
st = i;
break;
}
}
for(int i = N - ; i >= ; i --) {
if(s[i] == '<') {
en = i;
break;
}
}
printf("%d\n", min(st, N - - en));
}
}
return ;
}

C. Playlist

优先队列 不是很会 看了题解才知道 555

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 3e5 + ;
int N, K;
int sum[maxn];
int maxx = ; struct Node{
long long t;
long long b;
}node[maxn]; bool cmp(const Node &n1, const Node &n2) {
return n1.b > n2.b;
} int main() {
scanf("%d%d", &N, &K);
for(int i = ; i <= N; i ++)
cin >> node[i].t >> node[i].b; long long sum = , ans = ;;
priority_queue<long long, vector<long long>, greater<long long> > q;
sort(node + , node + + N, cmp);
for(int i = ; i <= N; i ++) {
q.push(node[i].t);
sum += node[i].t;
if(q.size() > K) {
sum -= q.top();
q.pop();
}
ans = max(ans, sum * node[i].b);
} cout << ans << endl; return ;
}

D. Minimum Triangulation

代码:

#include <bits/stdc++.h>
using namespace std; int N;
int dp[]; int main() {
dp[] = ;
for(int i = ; i <= ; i ++)
dp[i] = dp[i - ] + (i * (i - )); scanf("%d", &N);
printf("%d\n", dp[N]);
return ;
}