题目链接:http://codeforces.com/gym/101190/attachments
题意:给了一堆逻辑表达式,判断是否对于所有的整数(-2^15 - 2^15-1)范围类的数,都满足逻辑表达式或者都不满足这些逻辑表达式,还有是部分满足,部分满足需要输出这些区间。没说清楚,题目挺短的,可以自己读下。

解法: bitset暴力,注意把下标修正到正数,设个offset就好。

#include<bits/stdc++.h>
using namespace std;
const int offset = 32768;
int main()
{
    freopen("hard.in","r",stdin);
    freopen("hard.out","w",stdout);
    string str;
    bitset<65536> ans;
    while(getline(cin, str))
    {
        stringstream ss(str);
        string s;
        bitset<65536> tmp;
        tmp.flip();
        while(1)
        {
            ss >> s;
            ss >> s;
            bitset<65536> make;
            if(s == ">=")
            {
                ss >> s;
                int x;
                sscanf(s.c_str(), "%d", &x);
                for(int i = x + offset; i < 65536; i++) make.set(i);
            }
            else
            {
                ss >> s;
                int x;
                sscanf(s.c_str(), "%d", &x);
                for(int i = x + offset; i >= 0; i--) make.set(i);
            }
            tmp &= make;
            if(!(ss >> s)) break;
            if(s == "||") break;
        }
        ans |= tmp;
    }
    if(ans.count() == 65536)
    {
        puts("true");
        return 0;
    }
    else if(ans.count() == 0)
    {
        puts("false");
        return 0;
    }
    vector<pair<int, int> > Ans;
    for(int i = 0; i < 65536; i++)
    {
        if(ans[i])
        {
            int pos = i;
            while(pos + 1 < 65536 && ans.test(pos + 1)) pos++;
            Ans.push_back(make_pair(i, pos));
            i = pos;
        }
    }
    for(int i = 0; i < Ans.size(); i++)
    {
        if(Ans[i].first == 0 || Ans[i].second == 65535)
        {
            if(Ans[i].first == 0)
                printf("x <= %d", Ans[i].second - offset);
            else
                printf("x >= %d", Ans[i].first - offset);
        }
        else
            printf("x >= %d && x <= %d", Ans[i].first - offset, Ans[i].second - offset);
        if(i != Ans.size() - 1) printf(" ||");
        printf("\n");
    }
}