"CSPJ-S 2019 ten even measured" Day1

Because copyright reasons, face and hold the title.

sequence

Solution

Because the length of the interval is monotone, it is possible to delete section to delete the enumeration, and then enumerate all the length of the interval, determining the linear complexity \ (O (n-2logn ^) \) , can pass. You can first count the number of times each number appears, do \ (O (nlogn) \) complexity.

This question is also a foot emulated. First count the number of times each number appears, enumerated the right range, see if you can put the interval left to the right. Until there are no duplicate numbers. Complexity or \ (O (nlogn) \) , because the data needs a large range of discrete look.

To sum up, the question people cool heart, the range of data to be small, the topic was also good. Write code ruler emulated it.

Code

#include <bits/stdc++.h>
using namespace std;
#define re register
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> P;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int read() {
    int x = 0, f = 0; char ch = 0;
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return f ? -x : x;
}
map <int, int> mp;
int a[N];
int main(){
    int n = read(), cnt = 0;
    for (int i = 1; i <= n; i++){
        a[i] = read(); 
        if (mp[a[i]] == 1) cnt++; 
        mp[a[i]]++;
    }
    int ans = INF;
    for (int r = 1, l = 1; r <= n; r++){
        if (--mp[a[r]] == 1) cnt--;
        while (!mp[a[l]] && l <= r) mp[a[l++]]++;
        if (!cnt) ans = min(ans, r - l + 1);
    }
    printf("%d\n", ans);
    return 0;
}

digital

Solution

Hand count of seeking formulas, feeling a little Mobius inversion.
\ [\ Sum _ {i =
1, m | i} ^ n {i \% 10} = \ sum_ {i = 1} ^ {\ frac {n} {m}} m \ times i \% 10 \] If you go to write on the white violence, you can find the value of this formula is based on \ (10 \) for the period. Thought block then done on it, the complexity of the \ (O (T) \) , a constant large. To open long long.

In summary, the topic of this question people are still very cold heart, did not examine prefix and cheese, and gave a friendly range of data but does not rule out is to confuse the people, it is important to let me get a kinds of questions.

Code

#include <bits/stdc++.h>
using namespace std;
#define re register
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> P;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
ll read() {
    ll x = 0, f = 0; char ch = 0;
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return f ? -x : x;
}
int main(){
    int T = read();
    while (T--){
        ll n = read(), m = read();
        ll ans = 0;
        for (ll i = m; i <= n; i += m){
            if(i % 10 == 0) ans *= n / i, i *= n / i;
            ans += i % 10;
        }
        printf("%lld\n", ans);
    } 
    return 0;
}

backpack

Solution

The greedy thought, time to enter a first keyword, the keyword extracted a second time. The earlier priority level into the larger, the greater the time priority taken later, can then dp. This step is not difficult.

Set \ (f_ {i, j} \) represents the \ (I \) one on top of the article, the \ (I \) at any time and the mass does not exceed the previous article \ (J \) is the maximum value. For load-bearing restrictions, it may be specified \ (j \) boundary. Transfer into two, the first section is coupled in \ (I \) value of the article before the article period. The second is the enumeration \ (I \) before loading, \ (I \) withdrawn after \ (K \) .

Complexity \ (O (the n-^ 3) \) , a good question.

Code

#include <bits/stdc++.h>
using namespace std;
#define re register
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000 + 10;
const int INF = 0x3f3f3f3f;
int read() {
    int x = 0, f = 0; char ch = 0;
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return f ? -x : x;
}
struct node{
    int l, r, w, s, v;
}a[N];
bool cmp(node a, node b){
    if (a.l != b.l) return a.l < b.l;
    return a.r > b.r;
} 
int dp[N][N];
int main(){
    int n = read(), S = read();
    for (int i = 1; i <= n; i++) a[i].l = read(), a[i].r = read(), a[i].w = read(), a[i].s = read(), a[i].v = read();
    sort(a + 1, a + n + 1, cmp);
    int ans = -INF; 
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= min(a[i].s, S); j++){
            int pre = 0; dp[i][j] = a[i].v;
            for (int k = 1; k < i; k++){
                if (a[i].r <= a[k].r) dp[i][j] = max(dp[i][j], dp[k][j + a[i].w] + a[i].v + pre);
                if (a[i].l >= a[k].r) pre += a[k].v;
            }
            ans = max(ans, dp[i][j]);
        }
    }
    printf("%d\n", ans);
    return 0;
}

toy

Solution

Grotesque shaped pressure dp, fog.

Your title is equivalent to \ (n \) a \ (m \) binary digits, and asked how many or any number of alternatives are all up \ (1 \) .

Bit mask, the first cuckoo.

Guess you like

Origin www.cnblogs.com/lyfoi/p/11616207.html