第一行两个整数N,X,其中N为Y集合元素个数,X如题所述,且1<=N<=50,1<=X<=1,000,000,000. 之后N行,每行一个整数yi,即集合Y中的第i个元素,且1<=yi<=1,000,000,000.
一个整数,表示最少删除多少个元素。
5 7 1 2 4 7 8
2
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <string> #include <cmath> #include <set> #include <queue> #include <algorithm> #include <vector> #include <map> using namespace std; #define esp 1e-8 const double PI = acos(-1.0); const int inf = 1000000005; const long long mod = 1000000007; //freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取 //freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中 int a[55], b[33], vis[55]; int main() { int n, x, i, j; while (~scanf("%d%d", &n, &x)) { for (i = 1; i <= n; ++i) scanf("%d", &a[i]); memset(b, 0, sizeof(b)); int mm = 100; int s = 0; memset(vis, 0, sizeof(vis)); for (i = 0; i <= 30; ++i) { if ((1 << i) > x) break; if (!((1 << i) &x)) { for (j = 1; j <= n; ++j) { if (a[j] & (1 << i)) { vis[j] = 1; } } } } for (i = 0; i <= 30; ++i) { if ((1 << i) > x) break; if ((1 << i) & x) { s += (1 << i); for (j = 1; j <= n; ++j) { if (((a[j] & (1 << i))) && (a[j] <= x) && !vis[j]) { b[i] ++; } } mm = min(mm, b[i]); } } printf("%d\n", mm); } }