Mind Control
Topic links: https://codeforces.com/contest/1290/problem/A
Meaning of the questions:
A total of n items, each item has its own value.
N existing personal, everyone can be randomly or sequentially from scratch tail away a gift
M where you came in the first place, and you can specify that they take personal control X head or tail of gift
You can get at least ask how much value items
analysis:
We make K = min (X, M-1), it is because you can get a gift worth only by the personal influence of the former M-1
At this point you in front of you by K individuals can control, M - 1 - K individuals will not be out of your control, we make M - 1 - K = C
We let 0 <= i <= K, 0 <= j <= C, i mean you can control from the beginning and you let him take the gift of people Number
j means that you can not control the number of gifts and took him from the beginning, and then took the gift from the tail number is (K - i) + (C - j)
So to turn heads when you take the rest of the gift is a gift on a [i + j + 1], the rest of the tail as a gift to a [n - (K - i) - (Cj)]
Because the data is subject to a range of relatively small, so we can enumerate violence N ^ 2 friends
While enumerating the minimum we should pay attention because the number of j can not be controlled, so we have to take enumerate all the j
While the number i is that we can control, so we have to take the maximum of all i enumeration in
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 2e5 + 10; ll a[N] , ans; int main() { int t , n , m , k , c , x; cin >> t; while(t --) { cin >> n >> m >> x ; for(int i = 1 ; i <= n ; i ++) cin >> a[i]; k = min(x , m - 1) , c = m - 1 - k , ans = 0 ; for(int i = 0 ; i <= k ; i ++) { ll now = (0x3f3f3f3f3f3fll); for(int j = 0 ; j <= c ; j ++) now = min(now , max(a[i + j + 1] , a[n - (k - i) - (c - j)])); ans = max(ans , now); } cout << ans << '\n'; } return 0; }
Irreducible Anagrams
Topic links: https://codeforces.com/contest/1290/problem/B
Meaning of the questions:
Defined anagram, two characters refer to the same string.
Reducible defined anagram, represents two strings can be split into k sub-string and each substring is the anagram.
irreducible anagram that does not meet the criteria.
You are given a string, and then ask q times, each time asking for you l, r. Ask you [l, r] of this string, can find an irreducible anagram.
analysis:
Difficulty in item difficulty
Not difficult to find when the following is true irreducible anagram
①, a string of 1
②, the first string is not the same
③, there are three or more different character strings
①② direct determination operation O1, count the number of each character prefix pretreatment operation ③, each inquiry traversing it again
#include<bits/stdc++.h> #define rep(i,a,n) for (int i=a;i<=n;i++) using namespace std; const int N = 3e5 + 10; int cnt[N][37] , n , l , r; string s; int main() { cin >> s; rep(i , 1 , s.size()) { rep(j , 0 , 25) cnt[i][j] = cnt[i - 1][j]; cnt[i][s[i - 1] - 'a'] ++ ; } cin >> n; while(n --) { cin >> l >> r; if(l == r) {cout << "Yes" << '\n' ; continue ;} if(s[l - 1] != s[r - 1]){cout << "Yes" << '\n' ; continue ;} int tot = 0; rep(j , 0 , 25) if(cnt[r][j] - cnt[l - 1][j]) tot ++; if(tot >= 3) cout << "Yes" << '\n'; else cout << "No" << '\n'; } return 0; }
Summary: The first fight div1, the bottom of the T ^ T, points out much better