Summer N Tianle [articles] game --2019 Hang electric multi-school summer training camp (sixth)

I Hu Hansan and roll back .... had a shelf life of the title have to write it down.

The following explanations include:

\ [1002 【HDU-6635】 【1005 \\ HDU-6638】 【1006 \\ HDU-6639】 【1008 \\ HDU-6641】 【1012 \\ HDU-6645 [\]

[1002] LIS + violence HDU-6635 Nonsense Time

http://acm.hdu.edu.cn/showproblem.php?pid=6635

Reference: https://blog.csdn.net/henuyh/article/details/98845165

A given length of \ (n-\) of the two arrays \ (A, B \) , \ (B_i \) represents \ (A \) in the subscript \ (B_i \) is the number currently available, seeking \ (B_i \) corresponding \ (a \) in the LIS, \ (a \) is \ ([1, n] \ ) of the full array.

Since the data is randomly generated, LIS desired length \ (\ sqrt {n-} \) , the probability of deleting elements in the LIS as \ (\ FRAC {. 1} {\ sqrt {n-}} \) , so overall complexity: \ (O (n-\} n-sqrt {log (n-))) \) . First Finding all of the LIS, and then forward through the array from the \ (b \) , if you remove one element of it is re-evaluated in the LIS. You need to record the path of the LIS.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

const int maxn = 5e4+5;

int n;
int a[maxn];
int b[maxn];
int vis[maxn];
int ans[maxn];
int temp[maxn];
int path[maxn];
int used[maxn];

int solve() {
    int len = 0;
    for(int i = 1; i <= n; i++) {
        if(vis[a[i]] == 1) {
            continue;
        }
        int x = lower_bound(temp, temp+len, a[i]) - temp;
        if(x == len) {
            temp[len++] = a[i];
            path[i] = len;
        }
        else {
            temp[x] = a[i];
            path[i] = x + 1;
        }
    }
    memset(used, 0, sizeof(used));
    int x = len;
    for(int i = n; i >= 1; i--) {
        if(vis[a[i]] == 1) {
            continue;
        }
        if(path[i] == x) {
            used[a[i]] = 1;
            x--;
        }
    }
    return len;
}

int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        memset(vis, 0, sizeof(vis));
        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]);
        }
        ans[n] = solve();
        for(int i = n-1; i >= 1; i--) {
            vis[a[b[i+1]]] = 1;
            if(used[a[b[i+1]]] == 0) {
                ans[i] = ans[i+1];
            }
            else {
                ans[i] = solve();
            }
        }
        for(int i = 1; i <= n; i++) {
            printf("%d%c", ans[i], i==n?'\n':' ');
        }
    }
    return 0;
}

[1005] segment tree HDU-6638 Snowy Smile

http://acm.hdu.edu.cn/showproblem.php?pid=6638

Reference: https://blog.csdn.net/A_Thinking_Reed_/article/details/98778260

Given \ (n (\ leq 2000) \) weights and the corresponding coordinate points, find the maximum value and the weight matrix.

Every enumeration upper and lower boundaries, each segment tree to add a little, maintaining the largest sub-segment within the upper and lower boundaries and [range] and the largest sub-segment, may have to pay attention to several points on the boundary moves in a straight line on the current, the same after all points on the boundary should have been updated when moving the lower boundary to update \ (ANS \) .

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

const int maxn = 2e3+5;

struct node{
    int x, y;
    ll val;
    bool operator < (const node &q) const {
        if(y == q.y) {
            return x < q.x;
        }
        return y > q.y;
    }
}p[maxn];

struct NODE {
    ll sum, lsum, rsum, maxsum;
}T[maxn << 2];

int n; 
vector<int> vx, vy;

int get_xid(int x) {
    return lower_bound(vx.begin(), vx.end(), x) - vx.begin() + 1;
}

int get_yid(int y) {
    return lower_bound(vy.begin(), vy.end(), y) - vy.begin() + 1;
}

void pushup(int rt) {
    T[rt].sum = T[rt<<1].sum + T[rt<<1|1].sum;
    T[rt].lsum = max(T[rt<<1].lsum, T[rt<<1].sum + T[rt<<1|1].lsum);
    T[rt].rsum = max(T[rt<<1|1].rsum, T[rt<<1|1].sum + T[rt<<1].rsum);
    T[rt].maxsum = max(T[rt<<1].rsum+T[rt<<1|1].lsum, max(T[rt<<1].maxsum, T[rt<<1|1].maxsum));
}

void build(int l, int r, int rt) {
    T[rt].sum = T[rt].lsum = T[rt].rsum = T[rt].maxsum = 0;
    if(l == r) {
        return ;
    }
    int mid = (l+r) >> 1;
    build(l, mid, rt<<1);
    build(mid+1, r, rt<<1|1);
    pushup(rt);
}

void update(int l, int r, int pos, int val, int rt) {
    if(l == r) {
        T[rt].sum = T[rt].lsum = T[rt].rsum = T[rt].maxsum = T[rt].sum+val;
        return ;
    }
    int mid = (l+r) >> 1;
    if(pos <= mid) {
        update(l, mid, pos, val, rt<<1);
    }
    else {
        update(mid+1, r, pos, val, rt<<1|1);
    }
    pushup(rt);
}

int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        vx.clear();
        vy.clear();
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            scanf("%d%d%lld", &p[i].x, &p[i].y, &p[i].val);
            vx.push_back(p[i].x);
            vy.push_back(p[i].y);
        }
        sort(vx.begin(), vx.end());
        vx.erase(unique(vx.begin(), vx.end()), vx.end());
        sort(vy.begin(), vy.end());
        vy.erase(unique(vy.begin(), vy.end()), vy.end());
        int new_n = vx.size();
        for(int i = 1; i <= n; i++) {
            p[i].x = get_xid(p[i].x);
            p[i].y = get_yid(p[i].y);
        }
        sort(p+1, p+1+n);
        ll ans = 0;
        int lst_y = -1;
        for(int i = 1; i <= n; i++) {
            if(lst_y == p[i].y) {
                continue;
            }
            build(1, new_n, 1);
            for(int j = i; j <= n; ) {
                int k;
                for(k = j; k <= n && p[k].y == p[j].y; k++) {
                    update(1, new_n, p[k].x, p[k].val, 1);
                }
                ans = max(ans, T[1].maxsum);
                j = k;
            }
            lst_y = p[i].y;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

[1006] thinking HDU-6639 Faraway

http://acm.hdu.edu.cn/showproblem.php?pid=6639

There \ (n \) two-dimensional coordinate points (soldiers), they have a common destination \ ((x_ {E}, Y_ {E}) \) , know \ (x_e \) and \ (y_e \) are ([0, m] \) \ in the range, but only they know their position \ ((x_i, y_i) \ ) about where the target is \ ((| x_ {i} -x_ {e} | + | y_ {i} -y_ {e} |) \% k_ {i} = t_ {i} \) ask you now how many possible targets \ ((x_e, y_e) \) .

The \ (| x_i - x_e | + | y_i - y_e | \) absolute value removed, then each point \ ((x_i, y_i) \ ) will be divided into four plane portions, a total of \ (n ^ 2 \) regions. Enumeration each region, the region may be calculated endpoint number. Since \ (LCM (2,. 3,. 4,. 5) = 60 \) , so only you need to enumerate \ (x_e \) and \ (y_e \) remainder die 60, \ (O (n-) \) determines the feasibility .

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m;
vector<int> vx, vy;

struct node {
    int x, y;
    int k, t;
}p[15];

int check(int a, int b) {
    for(int i = 1; i <= n; i++) {
        if((abs(a-p[i].x)+abs(b-p[i].y))%p[i].k != p[i].t) {
            return 0;
        }
    }
    return 1;
}

int cal(int x, int y) {
    if(y-x-1 < 0) {
        return 0;
    }
    return ((y-x-1)/60) + 1; 
}

int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        vx.clear();
        vy.clear();
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; i++) {
            scanf("%d%d%d%d", &p[i].x, &p[i].y, &p[i].k, &p[i].t);
            vx.push_back(p[i].x);
            vy.push_back(p[i].y);
        }
        vx.push_back(0);
        vx.push_back(m+1);
        vy.push_back(0);
        vy.push_back(m+1);
        sort(vx.begin(), vx.end());
        vx.erase(unique(vx.begin(), vx.end()), vx.end());
        int nx = vx.size();
        sort(vy.begin(), vy.end());
        vy.erase(unique(vy.begin(), vy.end()), vy.end());
        int ny = vy.size();
        ll ans = 0;
        for(int i = 0; i < nx-1; i++) {
            for(int j = 0; j < ny-1; j++) {
                for(int k = 0; k < 60; k++) {
                    for(int l = 0; l < 60; l++) {
                        if(check(vx[i]+k, vy[j]+l)) {
                            ans += 1ll*cal(vx[i]+k, vx[i+1])*cal(vy[j]+l, vy[j+1]);
                        }
                    }
                }
            }
        }
        printf("%lld\n", ans);
    }   
    return 0;
}

[1008] math HDU-6641 TDL

http://acm.hdu.edu.cn/showproblem.php?pid=6641

Written by his teammates, then sauce.

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#define lson node<<1
#define rson node<<1|1
using namespace std;
typedef long long ll;

const ll inf = 2e18;
const ll mod = 998244353;
const int maxn = 1e5 + 20;


ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}


int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        ll k, m;
        scanf("%lld%lld", &k, &m);
        ll ans = inf;
        int flag = 0;
        for (int i = 1; i <= 2000; i++) {
            ll n = k ^ i;
            int cnt = 0;
            int j = 1;
            for (; j <= 1000; j++) {
                if (gcd(j + n, n) == 1) {
                    cnt++;
                    if (cnt == m)
                        break;
                }
            }
            if ((n + j) == (i + n)) {
                ans = min(ans, n);
                flag = 1;
            }
        }
        if (flag)
            printf("%lld\n", ans);
        else
            printf("-1\n");
    }
}

[1012] Water title HDU-6645 permutation 2

http://acm.hdu.edu.cn/showproblem.php?pid=6645

I do not know why the game time to write topology ...

To row a sequence one person points on the line.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int a[100005];

int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        int n;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        sort(a, a+n);
        ll ans1 = 0, ans2 = 0;
        for(int i = n-1; i >= 0; i-=2) {
            ans1 = ans1 + 1ll*a[i];
        }
        for(int i = n-2; i >= 0; i-=2) {
            ans2 = ans2 + 1ll*a[i];
        }
        printf("%lld %lld\n", ans1, ans2);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/Decray/p/11365864.html