标签:turn ane memset file lis cpp out red scan
第一行两个整数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<bits/stdc++.h> #include<cstdio> const int maxn = 55; const int M = 0x3f3f3f3f; using namespace std; int a[maxn]; int vis[maxn]; int dis[maxn]; int logo[maxn]; int k[maxn]; int i,j; int main() { int n,x; while(scanf("%d %d",&n,&x)!=EOF) { int ans = 0; memset(vis, 0, sizeof(vis)); while(x) { vis[ans++] = x%2; x /= 2; } memset(logo, 0, sizeof(logo)); memset(dis, 0, sizeof(dis)); memset(k, 0, sizeof(k)); for(i=0; i<n; i++) { scanf("%d",&a[i]); int flag = a[i]; int d = 0; while(flag) { dis[d++] = flag % 2; flag /=2; if(dis[d-1] && !vis[d-1]) logo[i] = 1; } } int num = M; for(i=0; i<n; i++) { if(logo[i]) continue; int flag = a[i]; int d = 0; while(flag) { k[d++] += flag%2; flag /= 2; } } for(i=0; i<ans; i++) { if(!vis[i]) continue; num = min(k[i],num); } if(num == M) printf("%d\n",0); else printf("%d\n",num); } return 0; }
标签:turn ane memset file lis cpp out red scan
原文地址:http://www.cnblogs.com/ruruozhenhao/p/7619971.html