Summer N Tianle [articles] game --2019 cattle off summer school and more training camp (seventh)

Solutions include the following problem: \ (A \ \ \ B \ \ \ C \ \ \ D \ \ \ E \ \ \ J \)

Another: \ ([H] Pair digit dp \ be completed \) After all, I will not

Contest Address: https://ac.nowcoder.com/acm/contest/887#question

[A] String minimum representation

Given a string of sections take it into the least minimum string representation of the string after the output segment.

Sequentially enumerated from front to back, until the continuously shortening the length of the current prefix is the smallest representation can then again at the end of the output current from the start determination.

#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;

char s[205];
string temp;
int l;

int get_min() {
    int i = 0, j = 1;
    int k = 0;
    while(i < l && j < l && k < l) {
        int t = temp[(i+k)%l] - temp[(j+k)%l];
        if(t == 0) {
            k ++;
        }
        else {
            if(t > 0) {
                i = i + k + 1;
            }
            else {
                j = j + k + 1;
            }
            k = 0;
            if(i == j) {
                j ++;
            }
        }
    }
    return i < j ? i : j;
}

int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        scanf("%s", s);
        int n = strlen(s);
        int pos = 0;
        while(1) {
            temp = "";
            for(int i = pos; i < n; i++) {
                temp = temp + s[i];
            }
            l = temp.length();
            while(get_min() != 0) {
                l--;
            }
            pos = pos + l;
            for(int i = 0; i < l; i ++) {
                cout << temp[i];
            }
            if(pos == n) {
                printf("\n");
                break;
            }
            else {
                printf(" ");
            }
        }
    }
    return 0;
}

【B】 Irreducible Polynomial 数学

Given a unary \ (n \) times equation, asked if he could break it down into the multiplicative form.

Theorems question is, not necessarily equal to 3 times greater than, equal to 1 will be able, when need is determined equal to two \ (b ^ 2 - 4ac < 0 \) is established or if established, can.

#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[30];
 
int main() {0;
}
    int t;
    scanf("%d", &t);
    while(t--) {
        int n;
        scanf("%d", &n);
        for(int i = n; i >= 0; i--) {
            scanf("%d", &a[i]);
        }
        if(n >= 3) {
            printf("No\n");
            continue;
        }
        if(n == 1) {
            printf("Yes\n");
            continue;
        }
        if(a[1]*a[1]-4*a[0]*a[2] < 0) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    return 0;
}

[C] Governing sand greedy

I do not know why the game when we do not see the "c <= 200" this condition, then his teammates knocked a tree line weight maintenance, although had also wasted a lot of time, school brother also pit ... the following is a positive solution after the game to write (probably).

Given \ (n \) trees, each with its height \ (H (\ leq1e ^ 9) \) , cut down the cost of \ (c (\ leq 200) \) and the number \ (p (\ 1E ^ 9 Leq) \) . Now we need to get the highest number of trees accounted for more than 50%, the minimum to ask how much it cost.

In fact, various sorting greedy just fine.

#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 = 1e5+5;

int n;
ll sum[maxn];
ll cost[205];
ll numh[maxn];
vector<ll> v;
struct node {
    ll h, c, p;
    bool operator < (const node &q) const {
        return h < q.h;
    }
}a[maxn];

int getid(ll x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;
}

int main() {
    while(~scanf("%d", &n)) {
        v.clear();
        for(int i = 1; i <= n; i++) {
            scanf("%lld%lld%lld", &a[i].h, &a[i].c, &a[i].p);
            v.push_back(a[i].h);
        }
        sort(a+1, a+1+n);
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        memset(sum, 0, sizeof(sum));
        memset(numh, 0, sizeof(numh));
        for(int i = 1; i <= n; i++) {
            int id = getid(a[i].h);
            sum[id] += sum[id-1] + 1ll*a[i].p*a[i].c;
            numh[id] += numh[id-1] + 1ll*a[i].p;
        }
        ll ans = 1e18;
        memset(cost, 0, sizeof(cost));
        int new_n = v.size();
        for(int i = 1; i <= n; i++) {
            int id = getid(a[i].h);
            ll temp = sum[new_n] - sum[id]; // 删掉所有比它高的树的代价
            ll num = numh[id] - numh[id-1]; // 这种高度的树的数量
            ll num_small = numh[id-1];      // 比他矮的树的数量
            // cout << temp << "  " << num << "  " << num_small << endl;
            if(num > num_small) {           // 不用砍了
                ans = min(ans, temp);   
                cost[a[i].c] += 1ll*a[i].p;
                continue;
            }
            ll more = num_small - num + 1;  // 需要砍掉多少
            for(int j = 1; j <= 200; j++) {
                if(cost[j] == 0) {
                    continue;
                }
                if(more - cost[j] >= 0) {
                    more -= cost[j];
                    temp = temp + cost[j]*j;
                }
                else {
                    temp = temp + more*j;
                    more = 0;
                }
                if(more == 0) {
                    break;
                }
            }
            cost[a[i].c] += 1ll*a[i].p;
            ans = min(ans, temp);
        }
        printf("%lld\n", ans);
    }
    return 0;
}

[D] Number water problem

Water problems do not write.

#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 get(int x) {
    int res = 0;
    while(x) {
        res++;
        x /= 10;
    }
    return res;
}

int main() {
    int n, p;
    while(~scanf("%d%d", &n, &p)) {
        int l = get(p);
        if(l > n) {
            printf("T_T\n");
            continue;
        }
        printf("%d", p);
        for(int i = l+1; i <= n; i++) {
            printf("0");
        }
        printf("\n");
    }
    return 0;
}

[E] Find the median segment tree

Reference: http://keyblog.cn/article-189.html

Fancy subject, in fact, given two arrays L, R, and an empty sequence, for the first \ (I \) for LR is put \ ([L_i, R_i] \ ) Each number in the sequence is added, and then the median output in the current sequence.

The main trouble is to write some + 1 / -1 will be very easy mistake, especially my use of this \ (vector \) discrete, I was more than a -1 inserted Let subscript 1 from the start, one way or another with arrays can circumvent many of + 1 / -1. Realization look at the code.

#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 = 8e5+5;

ll x[maxn], y[maxn];
ll val[maxn<<2], lazy[maxn<<2];
vector<ll> v;

int getid(ll x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

void pushup(int rt) {
    val[rt] = val[rt<<1] + val[rt<<1|1];
}

void pushdown(int l, int r, int rt) {
    int mid = (l+r) >> 1;
    val[rt<<1] += (v[mid]-v[l])*lazy[rt];
    val[rt<<1|1] += (v[r]-v[mid])*lazy[rt];
    lazy[rt<<1] += lazy[rt];
    lazy[rt<<1|1] += lazy[rt];
    lazy[rt] = 0;
}

void build(int l, int r, int rt) {
    if(l == r) {
        val[rt] = lazy[rt] = 0;
        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 l, int r, int rt) {
    if(L <= l && r-1 <= R) {
        val[rt] += (v[r]-v[l]);
        lazy[rt] ++;
        return ;
    }
    if(lazy[rt]) {
        pushdown(l, r, rt);
    }
    int mid = (l+r) >> 1;
    if(L < mid) {
        update(L, R, l, mid, rt<<1);
    }
    if(R >= mid) {
        update(L, R, mid, r, rt<<1|1);
    }
    pushup(rt);
}

ll query(int l, int r, int rt, ll x) {      // 找第 x 大的数
    if(l == r-1) {
        ll t = val[rt] / (v[r]-v[l]);
        return v[l] + (x-1)/t;
    }
    if(lazy[rt]) {
        pushdown(l, r, rt);
    }
    int mid = (l+r) >> 1;
    if(val[rt<<1] >= x) {
        return query(l, mid, rt<<1, x);
    }
    else {
        return query(mid, r, rt<<1|1, x-val[rt<<1]);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    v.clear();
    ll a1, b1, c1, m1;
    ll a2, b2, c2, m2;
    scanf("%lld%lld%lld%lld%lld%lld", &x[1], &x[2], &a1, &b1, &c1, &m1);
    scanf("%lld%lld%lld%lld%lld%lld", &y[1], &y[2], &a2, &b2, &c2, &m2);
    for(int i = 3; i <= n; i++) {
        x[i] = (a1*x[i-1]+b1*x[i-2]+c1) % m1;
        y[i] = (a2*y[i-1]+b2*y[i-2]+c2) % m2;
    }
    for(int i = 1; i <= n; i++) {
         ll tx = x[i];
        ll ty = y[i];
        x[i] = min(tx, ty) + 1;
        y[i] = max(tx, ty) + 1 + 1; // 多 +1 方便区间操作
        v.push_back(x[i]);
        v.push_back(y[i]);
    }
    v.push_back(-1);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int new_n = v.size();
    ll sum = 0;
    build(1, new_n, 1);
    for(int i = 1; i <= n; i++) {
        int l = getid(x[i]);
        int r = getid(y[i]);
        update(l, r-1, 1, new_n, 1);
        sum = sum + (v[r] - v[l]);
        printf("%lld\n", query(1, new_n, 1, (sum+1)/2));
    }
    return 0;
}

[J], A + B problem title water

Actually not really want to call it a water problem, after all, to put my card, and obviously 10 lines to get something, the brain a faster pumping wrote 100 lines, spend not know how long ... the following code to make the title game

Water problems do not write.

#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;

ll f(ll x) {
    ll res = 0;
    while(x) {
        res = res*10 + x%10;
        x /= 10;
    }
    return res;
}

int main() {
    ll a, b;
    int t;
    scanf("%d", &t);
    while(t--) {
        scanf("%lld%lld", &a, &b);
        printf("%lld\n", f(f(a)+f(b)));
    }
    return 0;
}

Guess you like

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