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

This was going to say let go, forget or make it ...

The following explanations include:

\ [1001 【HDU-6614】 【1003 \\ HDU-6616】 【1007 \\ HDU-6620】 【1008 \\ HDU-6621】 【1010 \\ HDU-6623 [\]

[1001] thinking HDU-6614 AND Minimum Spanning Tree

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

We need to build a tree, so that the right side and the minimum value, the right side for the two points "&" value.

Suppose bit 101, and then the second connection; assumed to be 111, there would look at this point 8, and then it does not point connection.

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

int a[maxn];

int wei(int x) {
    int ans = 0;
    while(x) {
        ans ++;
        x /= 2;
    }
    return ans;
}

int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        int n;
        scanf("%d", &n);
        int x = wei(n);
        int s = 0;
        for(int i = 0; i < x; i++) {
            if((n>>i) & 1) {
                s++;
            }   
        }

        int ans = 0;
        if(s == x) {
            ans ++;
        }
        printf("%d\n", ans);
        for(int i = 2; i <= n; i++) {
            if(ans == 1 && i == n) {    
                printf("1\n");
                break;
            }
            for(int j = 0; j < x; j++) {
                if((i>>j) & 1) {
                    continue;
                }
                printf("%d%c", (1<<j), i==n?'\n':' ');
                break;
            }
        } 
    }
    return 0;
}

[1003] thinking HDU-6616 Divide the Stones

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

Given weight \ (1 \) to the \ (n-\) a \ (n-\) stones, so you divided into an equal weight, the number is also equal to \ (K \) group, to ensure \ (K \) is \ (n- \) divisor. Output particular allocation scheme.

Reference: https://www.cnblogs.com/isakovsky/p/11281662.html

First, if \ (1 \) to \ (n \) the sum does not divide \ (k \) , then it must not be assigned; otherwise it will be able to.

Set \ (n-m = / K \) . \ (m \) is the number assigned to each block of stone. We arranged such stones n \ (m * k \) matrix, assuming stone 12, divided into three groups.
\ [\ Begin {bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ 10 & 11 & 12 \ end {bmatrix} \]

  • m is an even number, each taking as long as each of the head and tail \ (m / 2 \) a can.
  • m is an odd number, the sum of the two is configured to increment from top to bottom 1 and the remaining odd number row is configured to increment, decrement line configured.
#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 main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        int n, k;
        scanf("%d%d", &n, &k);
        ll sum = 1ll*n*(n+1)/2;
        if(k == 1) {
            printf("yes\n");
            for(int i = 1; i <= n; i++) {
                printf("%d%c", i, i==n?'\n':' ');
            }
        }
        else if(sum % k) {
            printf("no\n");
        }
        else {
            printf("yes\n");
            if((n/k) % 2 == 0) {
                int x = n / k;
                int cnt = 0;
                for(int i = 1; i <= n/2; i++) {
                    printf("%d %d", i, n-i+1);
                    cnt += 2;
                    if(cnt == x) {
                        printf("\n");
                        cnt = 0;
                    }
                    else {
                        printf(" ");
                    }
                }
            }
            else {
                int x = n / k;
                int tot = 1 + 2*k - k/2;
                int temp = 1;
                for(int i = 1; i <= k; i++) {
                    for(int j = 1; j <= x-2; j++) {
                        if(j % 2 == 1) {
                            printf("%d ", n-(j-1)*k-i+1);
                        }
                        else {
                            printf("%d ", n-j*k+1+i-1);
                        }
                    }
                    printf("%d %d\n", temp, tot - temp);
                    tot ++;
                    temp += 2;
                    if(temp > k) {
                        temp = 2;
                    }
                }
            }
        }
    }
    return 0;
}

[1007] thinking HDU-6620 Just an Old Puzzle

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

Given a digital puzzle, I asked if he could be able to restore it to its original form (step 120 or less).

The classic problem Huarong deformation.

Theorem: reverse same parity, can be transformed into another, different parity reverse, can not be converted to each other.

#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[20];

int main( ) {
    int t;
    scanf("%d", &t);
    int flag, ans;
    while(t--) {
        ans = 0;
        for(int i = 1; i <= 16; i++) {
            scanf("%d", &a[i]);
            if(a[i] == 0) {
                flag = i / 4 + (i % 4 != 0);
            }
            else {
                for(int j = 1; j < i; j++) {
                    if(a[j] == 0) {
                        continue;
                    }
                    if(a[j] > a[i]) {
                        ans++;
                    } 
                }
            }
        }
        printf((4-flag) % 2 == ans % 2 ? "Yes\n" : "No\n");
    }
    return 0;
}

[1008] Chairman tree HDU-6621 K-th Closest Distance

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

Given \ (n-\) number, \ (Q \) queries, each query \ ([l, r] \ ) inside, \ (| A [I] - P | \) of \ (K \) a large number, and the mandatory online. Wherein \ (n \ leq 1e ^ 5 \ \ q \ leq 1e ^ 5 \)

When thinking about the game has been Chairman of the tree, it has no way this large constant k optimized away, then T a whole. It was found that law can change a deposit on the line, perhaps it should be called weights Chairman tree? QAQ

Chairman of the tree node is directly \ (1e ^ 6 \) values, not discrete, the number of occurrences of each value are statistics alone. Bipartite query \ ((p-mid, p + mid) \) the counted number of.

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

int n, m, cnt, new_n;
int a[maxn];
int root[maxn];
vector<int> v;
struct node {
    int l, r, sum;
}T[maxn*40];

void init() {
    v.clear();
    cnt = 0;
}

inline void update(int l, int r, int &x, int y, int val) {
    T[++cnt] = T[y];
    T[cnt].sum ++;
    x = cnt;
    if(l == r) {
        return ;
    }
    int mid = (l+r) / 2;
    if(mid >= val) {
        update(l, mid, T[x].l, T[y].l, val);
    }
    else {
        update(mid+1, r, T[x].r, T[y].r, val);
    }
}

inline int query(int L, int R, int l, int r, int x, int y) {
    if(L <= l && r <= R) {
        return T[y].sum - T[x].sum;
    }
    int mid = (l+r) / 2;
    int ans = 0;
    if(L <= mid) {
        ans += query(L, R, l, mid, T[x].l, T[y].l);
    }
    if(R > mid) {
        ans += query(L, R, mid+1, r, T[x].r, T[y].r);
    }
    return ans;
}

int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        init();
        int MAX = 1000000;
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
        }
        for(int i = 1; i <= n; i++) {
            update(1, MAX, root[i], root[i-1], a[i]);
        }
        int ans = 0;
        for(int i = 1; i <= m; i++) {
            int l, r, p, k;
            scanf("%d%d%d%d", &l, &r, &p, &k);
            l = l^ans;
            r = r^ans;
            p = p^ans;
            k = k^ans;
            
            int L = 0;
            int R = MAX;
            while(L <= R) {
                int mid = (L+R) >> 1;
                if(query(max(1, p-mid), min(MAX, p+mid), 1, MAX, root[l-1], root[r]) >= k) {
                    ans = mid;
                    R = mid - 1;
                }
                else {
                    L = mid + 1;
                }
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}

[1010] math HDU-6623 Minimal Power of Prime

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

Given a number \ (the n-\) , seeking its predisposition to house the largest number of index.

Consider \ (n ^ {1/5} \ ) prime numbers in the range, the minimum number of prime numbers within the calculation range is the number, then remove these primes give the remaining numbers \ (m \) , consider \ (m \) if greater than 10,009 (prime number is 1 ~ n ^ (1/5) in the range of the prime number, n ranges (10009,1e18), it is known at this time the minimum prime number 10009, the most power is the smallest prime number 4, are discussed m is 2,3,4, whether power to a prime number, if not, 1 is the power). Special sentenced to 1.

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

int vis[maxn], pri[maxn];
int tot;
ll n;

void prime() {
    for(int i = 2; i < maxn; i++) {
        if(vis[i] == 0) {
            pri[tot++] = i;
            for(int j = i*i; j < maxn; j+=i) {
                vis[j] = 1;
            }
        }
    }
}

int check(ll x) {
    int l = 0;
    int r = 1000000;
    while(l <= r) {
        int mid = (l+r) >> 1;
        if(1ll*mid*mid*mid == x) {
            return 1;
        }
        if(1ll*mid*mid*mid > x) {
            r = mid-1;
        }
        else{
            l = mid+1;
        }
    }
    return 0;
}

int main() {
    prime();
    int t;
    scanf("%d", &t);
    while(t--) {
        scanf("%lld", &n);
        if(n == 1) {
            printf("0\n");
            continue;
        }
        ll ans = n;
        for(int i = 0; i < tot; i++) {
            if(n == 1) {
                break;
            }
            if(n % pri[i] == 0) {
                int cnt = 0;
                while(n % pri[i] == 0) {
                    cnt ++;
                    n /= pri[i];
                }
                ans = min(ans, 1ll*cnt);
            }
        }
        if(n >= maxn) {
            ll s1 = (ll)sqrt(n);
            ll s2 = (ll)sqrt(s1);
            if(s2*s2*s2*s2 == n) {
                ans = min(ans, 4ll);
            }
            else if(s1*s1 == n) {
                ans = min(ans, 2ll);
            }
            else if(check(n)) {
                ans = min(ans, 3ll);
            }
            else {
                ans = min(ans, 1ll);
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Guess you like

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