Water a-uncowed Forces
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int N = 1e5 + 5;const int INF = 0x3f3f3f3f;in T Main (void) {int s[5] = {(), +, (), 250};int m[5], w[5], HS, hu;for (int i=0; i<5; ++i) {scanf ("%d", &m[i]) ;} for (int i=0; i<5; ++i) {scanf ("%d", &w[i]);} scanf ("%d%d", &hs, &hu); int ans = 0;for (int i=0; i<5; ++i) {ans + = max (3 * s[i], (250-m[i]) * s[i] * 10/2 50-50 * w[i]);} Ans + = HS * 100-hu * 50;PRINTF ("%d\n", ans); return 0;}
(two points) + greedy b-more cowbell
Test instructions: n items in a maximum of K boxes, each box up to two, ask the size of the box is the smallest number.
Analysis: Can be two-enumeration volume size, then determine whether to meet the conditions need to greedy, as the solution says, if k > N, then the volume is the largest single. Otherwise there must be n-k a box must put two items (solution equation), then the first choice combination volume small, that is, the first 2 * (N-K) Items together before and after, then select the maximum value and then 2*k-n the maximum value is the answer. So finding two points actually doesn't need to be used ...
#include <bits/stdc++.h>using namespace std;const int n = 1e5 + 5;int a[n];int main (void) {int n, k;scanf ("%d%d", &A Mp;n, &k); for (int i=1; i<=n; ++i) scanf ("%d", &a[i]); int ans = a[n];; for (int i=1; i<=n-k; ++i) {ans = max (ans, a[i] + a[2* (n-k)-i+1]);} printf ("%d\n", ans); return 0;}
Two-part version
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int N = 1e5 + 5;const int INF = 0x3f3f3f3f;in T A[n];bool vis[n];int N, k;int check (int s) {memset (Vis, false, sizeof (VIS)), int j = 1, ret = 0;for (int i=n; i>=1;- -i) {if (J < i) {if (A[j] + a[i] <= s) {vis[j] = vis[i] = true;j++;} Elsevis[i] = true;ret++;} else if (j = = i) {if (!vis[i]) Ret++;break;}} return ret;} int main (void) {scanf ("%d%d", &n, &k), for (int i=1; i<=n; ++i) {scanf ("%d", &a[i]);} if (n = = 1) {printf ("%d\n", a[1]); return 0;} int L = A[n], r = a[n-1] + a[n];while (l + 1 <= r) {int mid = (L + R) >> 1;if (check (mid) <= k) R = Mid;elsel = Mid + 1;} int ans = r;printf ("%d\n", ans); return 0;}
DP | | Mathematics/Construction c-alternative thinking
Test instructions: There are 01 strings, you can select any length of the string to do a flip (0->1, 1->0), ask the shape of the maximum length of 01010110 or 1010101.
Analysis: The middle break may be 00 or 11 or only one 1 or 0. For example , 10110101-10101010 that is, the blue part is flipped, the visible length is +1. There is also a:101 1110101-10110101 length +2, so ans = min (n, ret + 2);
The afternoon thought for a long time on-line DP practice, Dp[i][j][k] indicates that the first-digit number is the maximum length of J when the State is K. I basically want to say that I understand the third dimension, k = 0 means no change, k=1 means change, then according to test instructions there is a change, then from 1 to 2 is from the change to the same
Structure:
#include <bits/stdc++.h>using namespace Std;const int N = 1e5 + 5;char str[n];int main () {int n;scanf ("%d%s", &n , str); int ans = 1;for (int i=1; i<n; ++i) {ans + = (str[i]! = Str[i-1]);} printf ("%d\n", Min (n, ans + 2)); return 0;}
Dp:
#include <bits/stdc++.h>using namespace Std;const int N = 1e5 + 5;char str[n];int dp[n][2][3];int n;void _max (int &A mp;a, int b) {if (a < b) A = b;} int run (void) {memset (DP,-1, sizeof (DP));DP [0][0][0] = dp[0][1][0] = 0;for (int i=0; i<n; ++i) {for (int j=0; j<2; ++J) {for (int k=0; k<3; ++k) {if (dp[i][j][k] = =-1) continue;for (int y=k; y<3; ++y) {_max (Dp[i+1][j][y], dp[i][j][k] int c = str[i+1]-' 0 '; if (y = = 1) c ^= 1;if (c! = j) {_max (Dp[i+1][c][y], dp[i][j][k] + 1);}}}} int ret = 0;for (int i=0; i<2; ++i) {for (int j=0; j<3; ++j) {_max (ret, dp[n][i][j]);}} return ret;} int main (void) {scanf ("%d", &n), scanf ("%s", str + 1);p rintf ("%d\n", run ()); return 0;}
Codeforces Round #334 (Div. 2)