# uva 565 - Pizza Anyone?

+关注继续查看

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <stack>
#include <list>
using namespace std;

const int MAXN = 100;
char G[MAXN][40]; //存储输入的字符串（注意数组的大小）
int P[16]; //存储每一个状态
int m, ans, len, flag;

//处理问题的函数
void solve(int cnt) {
int i, j;
int pos = 15;
memset(P, -1, sizeof (P)); //初始化为-1
while (pos >= 0) {
P[pos] = cnt & 1;
pos--;
cnt >>= 1;
}
//搜索只要每个人都满足即可判断这种情况就是满足的解
for (i = 0; i < len; i++) {
flag = 0;
for (j = 0; G[i][j] != ';'; j++) {
if (G[i][j] == '+') {
j++;
int t = G[i][j] - 65;
if (P[t])
flag = 1;
}
if (G[i][j] == '-') {
j++;
int t = G[i][j] - 65;
if (P[t] == 0)
flag = 1;
}
}
if (flag == 0)//如果有一个不满足直接退出
return;
}
if (i == len)
ans = 1;
}

//输出函数
void output() {
if (ans) {
printf("Toppings: ");
for (int i = 0; i < 16; i++) {
if (P[i])
printf("%c", i + 65);
}
printf("\n");
} else
printf("No pizza can satisfy these requests.\n");
}

//主函数
int main() {
int i;
while (gets(G[0]) && strcmp(G[0], ".")) {
i = 1;
ans = 0;
while (gets(G[i])) {
if (strcmp(G[i], ".") == 0)
break;
i++;
}
len = i;
m = 65535;//2的16次方减1
while (m) {//枚举每一种情况
solve(m);
if (ans)//找到以后退出不用继续搜索
break;
m--;
}
output();
}
return 0;
}

|
4月前
Uva10001 Garden of Eden
Uva10001 Garden of Eden
20 0
|
4月前
uva10152 ShellSort
uva10152 ShellSort
24 0
|
4月前
uva10038 Jolly Jumpers
uva10038 Jolly Jumpers
16 0
|
4月前
uva10112 Myacm Triangles
uva10112 Myacm Triangles
18 0
|
4月前
uva375 Inscribed Circles and Isosceles Triangles
uva375 Inscribed Circles and Isosceles Triangles
18 0
UVa 10082 WERTYU
UVa 10082 WERTYU
83 0
|

UVA 10325
1516 0
uva 10273 Eat or Not to Eat?

765 0