The NOD 1315 legal set of integers (thinking + simulation)

Source: Internet
Author: User

Portal
An integer set of S is legal and refers to any subset of S SubS have fun (SubS)! =x, where X is a fixed integer, fun (A) is defined as follows:
A is a set of integers with n elements in a, a0,a1,a2,..., an-1, which are defined as: Fun (A) =a0 or A1 or ... or An-1;fun ({}) = 0, that is, the function value of the empty set is 0. Where, or is or is manipulated.
Now give you a set Y with the value of the integer x, ask at least how many elements in the set Y delete can make the set y legal?

For example: y = {1,2,4},x=7; Y is obviously not legal now, because 1 or 2 or 4 = 7, but after removing any element, Y will be legal. So the answer is 1.
Input
The first line is two integers n,x, where N is the number of Y-collection elements, as described by X title, and 1<=n<=50,1<=x<=1,000,000,000.
Then n rows, one integer yi per line, that is, the first element in the set Y, and 1<=yi<=1,000,000,000.
Output
An integer that represents the minimum number of elements to delete.
Input example
5 7
1
2
4
7
8
Output example
2

Problem Solving Ideas:
The problem is still very attention to detail, I was wrong many times, are tears ah. Well, don't say a word, talk about the problem-solving ideas:
Because it is guaranteed or, so the X is converted to 2 after considering the 1 of the one on the line, and then notice that the larger than the X can skip directly, because the logic or later is certainly larger than the X, it is impossible to equal to X, and then the need to skip is that the current x of this bit is 0, However, this bit of the number in the collection happens to be 1, so also skip, logical or not X after, so just consider X is 1 of those bits on the line, and then find the smallest.

#include <iostream>#include <cstring>#include <cstdio>using namespace STD;Const intMAXN = the;typedef Long LongLL; LL A[MAXN], TP[MAXN];intB[MAXN];intMain () {LL n, x; while(Cin&GT;&GT;N&GT;&GT;X) {memset(b,0,sizeof(b)); LL tmp = x;intCNT =0, M =0; while(TMP) {b[cnt++] = (TMP &1); TMP >>=1; } LL xx; for(intI=0; i<n; i++) {Cin>>xx;if(xx <= x) {intCnt1 =0; LL tt = XX; while(TT) {intTTT = (tt&1);if(TTT && (!b[cnt1]))GotoENDW; tt>>=1;                cnt1++;            } a[m++] = XX;        } ENDW:; }intMin =999999; for(intj=0; j<cnt; J + +) {if(B[j]) {intAns =0; for(intI=0; i<m; i++) {if(a[i]&1) ans++; a[i]>>=1;            } min = min (min, ans); }Else                 for(intI=0; i<m; i++) a[i]>>=1; }cout<<Min<<endl; }return 0;}/**3 11257129521742182015120**/

NOD 1315 Legal set of integers (think + simulate)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.