uva-565-枚举

时间:2023-03-10 00:34:56
uva-565-枚举

16个披萨配料,选出一种组合满足所有人的需求,当然,如果某个人不喜欢A,结果里不包含A也是满足这个人的.只要答案满足题意既可,答案不唯一,special judge

用位枚举

#include <stdio.h>
#include<iostream>
#include <string.h>
#include<memory.h>
using namespace std;
const int N = ;
int yes[] = { };
int no[] = { };
const string out = "Toppings: ";
int total = ;
int main()
{
char input2[];
while (gets(input2) != NULL)
{
if(input2[] == '.')
{
int i = ;
for(i = ; i < ( << ); i++)
{
int k = ;
for(; k < total; k++)
{
if((yes[k] & i) | (no[k] & (~i)))
continue;
else
break;
}
if(k == total)
break;
}
if(i == ( << ))
{
cout << "No pizza can satisfy these requests." << endl;
}
else
{
char ss[];
memset(ss, , sizeof(ss));
int index = ;
for(int k = ; k < ; k++)
{
if(i & ( << k))
ss[index++] = k + 'A';
}
cout << out;
cout << ss << endl;
}
memset(yes, , sizeof(yes));
memset(no, , sizeof(no));
total = ;
}
else
{
for(int i = ;input2[i]!=';'; i=i+)
{
if(input2[i] == '+')
{
char cc = input2[i+];
yes[total] = (yes[total]) | ( << (cc - 'A'));
}
else
{
char cc = input2[i+];
no[total] = (no[total]) | ( << (cc - 'A'));
}
}
++total;
}
}
return ;
}