当前位置:网站首页>Zoo [csp2020]

Zoo [csp2020]

2020-11-09 19:33:36 AK_DREAM

Topic

https://www.luogu.com.cn/problem/P7076

Answer key

This should be the most signed in question

Feed is common \(c\) Kind of ,1e8 There is no room for , First, the feed number should be re labeled

Note that there is no need to discretize ( Sort and de duplicate ), because \(q_i\) Different from each other , So just put the number \(i\) The number of the feed is regarded as \(i\) that will do ( What is the sign in question )

First of all, for existing animals , Deal with it first \(K\) Which of the animals is 1

Then scan through all the requirements to find out which feed to buy

Finally, scan all the requirements again and work out \(K\) Which of the bits can be 1

Suppose there is \(x\) It can be 1, The answer is \(2^x-n\)

Be careful :

  1. The answer may explode long long need unsigned long long
  2. If \(n=m=0,k=64\), So the answer is \(2^64\), Explosive unsigned long long... Special judgment required

It feels like 2 Hang up 5pts...

#include <bits/stdc++.h>
#define N 1000005
using namespace std;
typedef unsigned long long ull;

template <typename T>
inline void read(T &num) {
	T x = 0; char ch = getchar();
	for (; ch > '9' || ch < '0'; ch = getchar());
	for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ '0');
	num = x; 
}

int n, m, c, k, p[N];
ull a[N], S, ans, fst;
bool buy[N], ok[N];

void solvebuy() {
	for (int i = 1; i <= m; i++) {
		if ((S>>p[i])&1) buy[i] = 1;
	}
}
void solveans() {
	for (int i = 0; i < k; i++) ok[i] = 1;
	for (int i = 1; i <= m; i++) {
		if (!buy[i]) ok[p[i]] = 0;
	}
	int cnt = 0;
	for (int i = 0; i < k; i++) if (ok[i]) cnt++;
	ans = (1ull << cnt) - n;
} 

int main() {
	read(n); read(m); read(c); read(k);
	if (!n && !m && k == 64) {
		puts("18446744073709551616");
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		read(a[i]); S |= a[i];
	}
	for (int i = 1; i <= m; i++) {
		read(p[i]); read(fst);
	}
	solvebuy();
	solveans();
	cout << ans << endl; //%lld It doesn't seem very good  
	return 0;
} 

版权声明
本文为[AK_DREAM]所创,转载请带上原文链接,感谢