Game links
A title
The meaning of problems
\ (n \) Personal Everyone has their favorite drink \ (vechorka \) taste, and now you \ (\ lceil n / 2 \ rceil \) box \ (vechorka \) , there are two bottles per case, up to ask how many people have to get your favorite flavor.
Thinking
We first recorded how many people like the taste of each, and then in order to get your favorite flavor maximum then we must give priority to scrape together an even number, the even number after considering the remaining taste necessarily \ (1 \) , on the matter how points can only meet half of the people.
Code to achieve the following
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n, k;
int a[maxn], num[maxn];
int main() {
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
num[a[i]]++;
}
int ans = 0;
int tot = (n + 1) / 2;
for(int i = 1; i <= k; ++i) {
ans += num[i] / 2 * 2;
tot -= num[i] / 2;
num[i] %= 2;
}
ans += tot;
printf("%d\n", ans);
return 0;
}
B title
The meaning of problems
You just want to use the \ (n \) operations so that the total number of candies \ (k \) , operations are divided into two types:
- Increasing the number of the last increase in \ (+ 1 \) candy;
- Reduce \ (1 \) candy.
Thinking
Half \ (the Check \) .
Code to achieve the following
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n, k;
bool check(int x) {
return (1LL * x * x + 3LL * x) / 2 - n >= k;
}
int main() {
scanf("%d%d", &n, &k);
int ub = n, lb = 1, mid, ans = 0;
while(ub >= lb) {
mid = (ub + lb) >> 1;
if(check(mid)) {
ans = mid;
ub = mid - 1;
} else {
lb = mid + 1;
}
}
printf("%d\n", n - ans);
return 0;
}
C title
The meaning of problems
A total of \ (2n \) individuals, the first row of numbers from \ (1 \) to \ (the n-\) , the second row is, you want to select any of the now more than one person making the total height maximum, but note that only the same number to have a person, not a number of adjacent words of the same row.
Thinking
\ (dp [i] [j ] \) represents the number \ (I \) who selected state is \ (J \) maximum height when, \ (J = 0 \) represents the first row is selected, \ ( j = 1 \) from the second row, \ (J = 2 \) is not selected, then the \ (dp [i] [0 ] = max (dp [i-1] [1], dp [i-1] [2]) + a [i ], dp [i] [1] = max (dp [i-1] [0], dp [i-1] [2]) + b [i], dp [i] [2] = max (DP [-I. 1] [0], DP [-I. 1] [. 1], DP [-I. 1] [2]) \) .
Code to achieve the following
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n;
int a[maxn], b[maxn];
LL dp[maxn][3];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for(int i = 1; i <= n; ++i) {
scanf("%d", &b[i]);
}
for(int i = 1; i <= n; ++i) {
dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
dp[i][2] = max(dp[i-1][0], max(dp[i-1][1], dp[i-1][2]));
}
printf("%lld\n", max(dp[n][0], max(dp[n][1], dp[n][2])));
return 0;
}
D title
The meaning of problems
Defined \ (F \) function
if \ (P \ GEQ Q \) : \ (F (A1 ... AP, B1 ... BQ) = a_1a_2 \ DOTS A_ {P-Q +. 1} b_1a {P-Q + 2} B_2 \ DOTS A_ {P-. 1} B_ {Q-. 1} a_pb_q \) ;
if \ (P <Q \) : \ (F (A_1 \ DOTS a_p, B_1 \ DOTS b_q) = b_1b_2 ... B_ {Q-P a_1b_ P-Q {} +}. 1 A_2 \ A_ DOTS {P}. 1-B-Q {} a_pb_q. 1 \) .
Thinking
Bitwise Operators contribution, the first pretreatment \ (a_i \) length \ (len \) for the number \ (F \) contribution is then multiplied by a function of the length \ (len \) of the counted number.
Code to achieve the following
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 998244353;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n;
int a[maxn], pw[105], cnt[30];
LL dp[maxn][30];
int main() {
scanf("%d", &n);
pw[0] = 1;
for(int i = 1; i < 30; ++i) {
pw[i] = 1LL * pw[i-1] * 10 % mod;
}
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for(int i = 1; i <= n; ++i) {
int x = a[i], len = 0;
while(x) {
++len;
x /= 10;
}
cnt[len]++;
for(int j = 1; j <= 10; ++j) {
if(len >= j) {
int num = a[i];
for(int k = 0; k < j; ++k) {
int x = num % 10;
num /= 10;
dp[i][j] = (((dp[i][j] + 1LL * x * pw[k*2] % mod) % mod) + 1LL * x * pw[k*2+1] % mod) % mod;
}
int pp = 2 * j;;
for(int k = j; k < len; ++k) {
int x = num % 10;
num /= 10;
dp[i][j] = (dp[i][j] + 2LL * x * pw[pp] % mod) % mod;
++pp;
}
} else {
int num = a[i];
for(int k = 0; k < len; ++k) {
int x = num % 10;
num /= 10;
dp[i][j] = (((dp[i][j] + 1LL * x * pw[k*2] % mod) % mod) + 1LL * x * pw[k*2+1] % mod) % mod;
}
}
}
}
LL ans = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= 10; ++j) {
ans = (ans + 1LL * dp[i][j] * cnt[j] % mod) % mod;
}
}
printf("%lld\n", ans);
return 0;
}
E title
The meaning of problems
You configured \ (n \ times m \) of the formula and the matrix size is to require that all you \ (a \ times b \) within a sub-matrix and the minimum value.
Code to achieve the following
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 998244353;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n, m, a, b;
LL g, x, y, z;
int mp[3002][3002], dp[3002][3002];
deque<pii> q;
int main() {
scanf("%d%d%d%d", &n, &m, &a, &b);;
scanf("%lld%lld%lld%lld", &g, &x, &y, &z);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
mp[i][j] = g;
g = (1LL * g * x % z + y) % z;
}
}
for(int i = 1; i <= n; ++i) {
while(!q.empty()) q.pop_back();
for(int j = m; j >= 1; --j) {
while(!q.empty() && mp[i][j] < q.front().first) q.pop_front();
q.push_front({mp[i][j], j});
dp[i][j] = q.back().first;
while(!q.empty() && q.back().second >= j + b - 1) q.pop_back();
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
mp[i][j] = dp[i][j];
}
}
for(int j = 1; j <= m; ++j) {
while(!q.empty()) q.pop_back();
for(int i = n; i >= 1; --i) {
while(!q.empty() && mp[i][j] < q.front().first) q.pop_front();
q.push_front({mp[i][j], i});
dp[i][j] = q.back().first;
while(!q.empty() && q.back().second >= i + a - 1) q.pop_back();
}
}
LL ans = 0;
for(int i = 1; i <= n - a + 1; ++i) {
for(int j = 1; j <= m - b + 1; ++j) {
ans += dp[i][j];
}
}
printf("%lld\n", ans);
return 0;
}