HDU 6702 ^ & ^

这题
Bit operation is a common computing method in computer science ,Now we have two positive integers A and B ,Please find a positive integer C that minimize the value of the formula (A xor C) & (B xor C) .Sometimes we can find a lot of C to do this ,So you need to find the smallest C that meets the criteria .

For example ,Let’s say A is equal to 5 and B is equal to 3 ,we can choose C=1,3… ,so the answer we’re looking for C is equal to 1.

If the value of the expression is 0 when C=0, please print 1.

让 (A xor C) & (B xor C) 最小 反正 xor C 只要 C和 A&B 对齐就好 C == 0 输出 1

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
#define int long long

int a, b, c;

signed main() {
    int cas;
    cin >> cas;
    while(cas --) {
        cin >> a >> b;
        if(a & b) cout <<  (a & b) << endl;
        else cout << 1 << endl;
    }
    return 0;
}

1002 array

path

无源点 无汇点 找第K短路
有源点A* 没有的话

我们把 当前 下一次 (这里存 from 而不是 v 了)起点 + 总路程和 放入队列 // 出边的这个点放入队列存储
同时 考虑 把(from)这边的下一个次边 也放入队列 进行扩展

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 100;
typedef long long ll;

int n, m, cas, q, mak, tail;
int qes[maxn];
ll ans[maxn];
struct node {
    int u, pos;
    ll w;
    bool operator < (const node& a) const {
        return w > a.w;
    }
};

bool cmp(const node &a, const node &b) {
    return a.w < b.w;
}

vector<node> G[maxn];
priority_queue<node> que;
void ade(int a, int b, int c) {
    G[a].push_back(node {b, 0, c});
}

void init() {
    for(int i = 1; i <= n; i ++) G[i].clear();
    mak = 0;
    tail = 0;
    while(!que.empty()) que.pop();
}


signed main() {
    scanf("%d", &cas);
    while(cas --) {
        scanf("%d %d %d", &n, &m, &q);
        init();
        for(int i = 1, a, b, c; i <= m; i ++)
            scanf("%d %d %d", &a, &b, &c), ade(a, b, c);

        for(int i = 1; i <= q; i ++)
            scanf("%d", &qes[i]), mak = max(mak, qes[i]);

        for(int i = 1; i <= n; i ++) sort(G[i].begin(), G[i].end(), cmp);

        for(int i = 1; i <= n; i ++)
            if(!G[i].empty()) que.push(node {i, 0, G[i][0].w});

        while(!que.empty()) {
            node p = que.top(); que.pop();
            int u = p.u;
            ll w = p.w;
            if(w == 0) {
                while(1);
            }
            ans[++ tail] = w;
            if(tail == mak + 5) break;
            if(p.pos < (int)G[u].size() - 1)
                que.push(node {u, p.pos + 1, w - G[u][p.pos].w + G[u][p.pos + 1].w});
            int v = G[u][p.pos].u;
            if(!G[v].empty())
                que.push(node {v, 0, w + G[v][0].w});
        }
        for(int i = 1; i <= q; i ++)
            printf("%lld\n", ans[qes[i]]);
    }
    return 0;
}

Shuffle Card HDU

按找 之后放入顺序 倒序 vis标记 去重

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0);
const int maxn = 1e5 + 5;
int n, m, k, cas, sum;

int a[maxn], b[maxn];
bool vis[maxn];

signed main() {
    fastio;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    for(int i = 1; i <= m; i ++) cin >> b[i];

    bool f = 0;
    for(int i = m; i >= 1; i--) {
        if(!vis[b[i]]) {
        
            cout << b[i];
            f = 1;
            vis[b[i]] = 1;    cout << " ";
        }
    }

    for(int i = 1; i <= n; i ++) {
        if(!vis[a[i]]) {
            
            cout << a[i];
            f = 1;
            vis[a[i]] = 1;cout << " ";
        }
    }//cout << endl;

    return 0;
}

HDU 6708 Windows Of CCPC

一般分形简单题 模拟

#include <bits/stdc++.h>
using namespace std;

char ch[1500][1500];

void init() {
    for(int i = 1; i <= 9; i ++) {
        int l1 = (1 << i) + 1;
        int r1 = (1 << i) * 2;

        for(int k = 1; k < l1; k ++) {
            for(int j = l1; j <= r1; j ++) {
                ch[k][j] = ch[k][j - l1 + 1];
            }
        }

        for(int k = l1; k <= r1; k ++) {
            for(int j = l1; j <= r1; j ++) {
                ch[k][j] = ch[k - l1 + 1][j - l1 + 1];
            }
        }

        for(int k = l1; k <= r1; k ++) {
            for(int j = 1; j < l1; j ++) {
                if(ch[k - l1 + 1][j] == 'P') ch[k][j] = 'C';
                else ch[k][j] = 'P';
// ch[k][j] = ch[k - l1 + 1][j];
            }
        }
    }
}

int main() {
    ch[1][1] = 'C';
    ch[1][2] = 'C';
    ch[2][1] = 'P';
    ch[2][2] = 'C';
    int cas;
    init();
    scanf("%d", &cas);
    while(cas --) {
        int n;
        scanf("%d", &n);

        for(int i = 1; i <= (1 << n); i ++) {
            for(int j = 1; j <= (1 << n); j ++) {
                printf("%c", ch[i][j]);
            }
            puts("");
        }

    }
    return 0;
}

HDU 6709 Fishing Master

容易wa
我们肯定先爪最长时间顿的
剩下的 就是靠我们 贪心往里套
最后不够抓一条鱼的顿时间存下来,后面抓鱼的时候从这些时间中选出最大的剩余时间,抓鱼的时间会和顿最大相交,这样可以使时间(k-x)最小。

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0);
const int maxn = 1e5 + 5;
int n, m, k, cas, sum;

priority_queue<int> que;
int a[maxn];
signed main() {
    fastio;
    cin >> cas;
    while(cas --) {
        while(!que.empty()) que.pop();
        cin >> n >> k;
        sum = 0;
        for(int i = 1; i <= n; i ++) cin >> a[i];
        sort(a + 1, a + 1 + n, greater<int>{});
// cout << a[1] << endl;
        sum = k + a[1];
        int cnt = a[1]/k;
        if(a[1] % k) que.push(a[1] % k);
        int pos = 2;
        for(; pos <= n; pos ++) {
            if(cnt) {
                cnt += a[pos] / k;
                cnt --;
                sum += a[pos];
                if(a[pos] % k) que.push(a[pos] % k);
            } else break;
        }
        for(; pos <= n; pos ++) {
            int tmp = que.top();
            que.pop();
            sum += (k - tmp) + a[pos];
            que.push(a[pos]);
        }
        cout << sum << endl;
    }
    return 0;
}

K-th occurrence

以下代码 学姐写的 orz 强啊
套了好多数据结构orz

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 500000 + 10;

int tmp_1[maxn], tmp_2[maxn];
long long RANKP[maxn], height[maxn];
char str[maxn];
long long sa[maxn];
int N, Q;

struct Tree {
	int a[maxn];
	int ll[maxn], rr[maxn];
	void create(int k, int l, int r) {
		ll[k] = l;
		rr[k] = r;
		if(l >= r) {
			a[k] = height[l + 1];
			return;
		}
		int mid = (l + r) / 2;
		create(k << 1, l, mid);
		create(k << 1 | 1, mid + 1, r);
		a[k] = min(a[k << 1], a[k<<1|1]);
	}
	int queryl(int k, int p, int s) {
		if(a[k] >= s) return -1;
		if(ll[k] >= p) return -1;
		if(ll[k] == rr[k]) return ll[k];
		int ans = -1;
		if(ll[k<<1|1] < p && a[k<<1|1] < s)
			ans = queryl(k<<1|1, p, s);
		if(ans != -1)
			return ans;
		return queryl(k<<1, p, s);
	}
	int queryr(int k, int p, int s) {
		if(a[k] >= s)
			return -1;
		if(rr[k] < p)
			return -1;
		if(ll[k] == rr[k])
			return ll[k];
		int ans = -1;
		if(rr[k<<1] >= p && a[k<<1] < s)
			ans = queryr(k<<1, p, s);
		if(ans != -1)
			return ans;
		return queryr(k<<1|1, p, s);
	}
}sdt;

bool cmp(int *r, int a, int b, int i) {
	return r[a] == r[b] && r[a + i] == r[b + i];
}

int c[maxn];

void solssda(char str[], int sa[], int RANKP[], int height[], int n, int m) {
	n++;
	int i, j, p, *x = tmp_1, *y = tmp_2;
	for(i = 0; i < m; i++)
		c[i] = 0;
	for(i = 0; i < n; i++)
		c[x[i] = str[i]]++;
	for(i = 0; i < m; i++)
		c[i] += c[i - 1];
	for(i = n - 1; i >= 0; i--)
		sa[--c[x[i]]] = i;
	for(j = 1; j <= n; j <<= 1) {
		p = 0;
		for(i = n - j; i < n; i++)
			y[p++] = i;

		for(i = 0; i < n; i++)
			if(sa[i] >= j)
				y[p++] = sa[i] - j;
		for(i = 0; i < m; i++)
			c[i] = 0;
		for(i = 0; i < n; i++)
			c[x[y[i]]]++;
		for(i = 1; i < m; i++)
			c[i] += c[i - 1];
		for(i = n - 1; i >= 0; i--)
			sa[--c[x[y[i]]]] = y[i];
		swap(x, y);
		p = 1;
		x[sa[0]] = 0;
		for(i = 1; i < n; i++)
			x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
		if(p >= n)
			break;
		m = p;
	}
	int k = 0;
	n--;
	for(i = 0; i <= n; i++)
		RANKP[sa[i]] = i;
	for(i = 0; i < n; i++) {
		if(k)
			k--;
		j = sa[RANKP[i] - 1];
		while(str[i + k] == str[j + k])
			k++;
		height[RANKP[i]] = k;
	}
}

struct Data {
	int l, r, sum;
}T[maxn * 15];

int cnt = 0;


vector<int> vec;


int get(int x) {
	return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1;
}
void insert(int l, int r, int &now, int pre, int x) {
	++cnt;
	now = cnt;
	T[now] = T[pre];
	T[now].sum += 1;

	int mid = (l + r) / 2;
	if(l == r) return;

	if(mid >= x)
		insert(l, mid, T[now].l, T[pre].l, x);
	else
		insert(mid + 1, r, T[now].r, T[pre].r, x);
}
int query(int l, int r, int x, int y, int k) {
	if(l == r)
		return l;
	int mid = (l + r) / 2;
	int R_sum = T[T[y].r].sum - T[T[x].r].sum;
	if(k <= R_sum)
		query(mid + 1, r, T[x].r, T[y].r, k);
	else
		query(l, mid, T[x].l, T[y].l, k - R_sum);
}
int root[maxn];
void solve(int n){
    for(int i = 0; i < Q; i++) {
		int l, r, k;
		scanf("%lld%lld%lld", &l, &r, &k);
		int len = r - l + 1;
		int p = RANKP[l - 1];
		int pl = sdt.queryl(1, p, len);
		int pr = sdt.queryr(1, p, len);
		if(pl == -1)
			pl = 1;
		else
			pl += 1;
		if(pr == -1)
			pr = n;
		if(pr > n)
			pr = n;
		if(pl > n)
			pl = n;
		if(pr - pl + 1 < k) {
			printf("-1\n");
			continue;
		}
		k = pr - pl + 2 - k;
		int ans = query(1, vec.size(), root[pl - 1], root[pr], k);
		printf("%lld\n", vec[ans - 1]);
	}
}
void dos() {
	scanf("%d%d", &N, &Q);
	scanf("%s", str);
	long long n = N;
	str[n] = 0;
	solssda(str, sa, RANKP, height, n, 200);
	for(int i = 1; i <= n; i++)
		++sa[i];
	for(int i = 1; i <= n; i++)
		vec.push_back(sa[i]);
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for(int i = 0; i < n; i++)
		insert(1, vec.size(), root[i + 1], root[i], get(sa[i + 1]));
	height[n + 1] = height[n];
	sdt.create(1, 1, n);
    solve(n);
}

void inputs() {
	int cas;
	scanf("%lld", &cas);
	while(cas --)
		dos();
}

signed main() {
	inputs();
	return 0;
}