Bzoj 3668 noi2014 getting up difficult syndrome greedy

Source: Internet
Author: User

A bunch of nonsense ..

Given N operations (and, Or, different or ~ Select a number in m to maximize the value after N operations.

A great deal of water, such as soil, such as iron ..

This Nima is simply a question of water. We can discuss the following three situations when selecting each digit of a number:

1. When this bit is set to 0, the result obtained after N operations is set to 1. This is the ideal case. You must select 0.

2. Case 1 does not meet the requirement. If this parameter is set to 1, 1 is obtained after N operations and the value after 1 does not exceed M. In this case, we also select 1.

3. If the preceding two conditions are not met, the bitwise 0 must be smaller than the bitwise 1, which is more difficult than M.

So the question goes.

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 100100using namespace std;struct abcd{    int p,x;    int cross(int y)    {        if(p==0)            return x&y;        if(p==1)            return x|y;        return x^y;    }}a[M];int n,m;char s[100];int cross(int x){    int i;    for(i=1;i<=n;i++)        x=a[i].cross(x);    return x;}int main(){              int i,ans=0,now;    cin>>n>>m;    for(i=1;i<=n;i++)    {        scanf("%s",s);        if(s[0]=='A')            a[i].p=0;        else if(s[0]=='O')            a[i].p=1;        else            a[i].p=2;        scanf("%d",&a[i].x);    }    for(now=1;now<=m;now<<=1);    for(now>>=1;now;now>>=1)    {        if(cross(0)&now)            continue;        if(ans+now<=m&&cross(now)&now)            ans+=now;    }    printf("%d\n",cross(ans));}


Bzoj 3668 noi2014 getting up difficult syndrome greedy

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.