[UVA][bitmask暴搜] 565 - Pizza Anyone?@Morris' Blog|PChome Online 人新台
2013-03-29 20:01:50| 人751| 回0 | 上一篇 | 下一篇

[UVA][bitmask暴搜] 565 - Pizza Anyone?

0 收藏 0 0 站台


  Pizza Anyone? 

You are responsible for ordering a large pizza for you and your friends. Each of them has told you what he wants on a pizza and what he does not; of course they all understand that since there is only going to be one pizza, no one is likely to have all their requirements satisfied. Can you order a pizza that will satisfy at least one request from all your friends?


The pizza parlor you are calling offers the following pizza toppings; you can include or omit any of them in a pizza:

Input Code Topping
A Anchovies
B Black Olives
C Canadian Bacon
D Diced Garlic
E Extra Cheese
F Fresh Broccoli
G Green Peppers
H Ham
I Italian Sausage
J Jalapeno Peppers
K Kielbasa
L Lean Ground Beef
M Mushrooms
N Nonfat Feta Cheese
O Onions
P Pepperoni

Your friends provide you with a line of text that describes their pizza preferences. For example, the line

+O-H+P; 

reveals that someone will accept a pizza with onion, or without ham, or with pepperoni, and the line

-E-I-D+A+J; 

indicates that someone else will accept a pizza that omits extra cheese, or Italian sausage, or diced garlic, or that includes anchovies or jalapenos.

Input 

The input consists of a series of pizza constraints.

A pizza constraint is a list of 1 to 12 topping constraint lists each on a line by itself followed by a period on a line by itself.

A topping constraint list is a series of topping requests terminated by a single semicolon.

An topping request is a sign character (+/-) and then an uppercase letter from A to P.

Output 

For each pizza constraint, provide a description of a pizza that satisfies it. A description is the string ``Toppings: " in columns 1 through 10 and then a series of letters, in alphabetical order, listing the toppings on the pizza. So, a pizza with onion, anchovies, fresh broccoli and Canadian bacon would be described by:

Toppings: ACFO 

If no combination toppings can be found which satisfies at least one request of every person, your program should print the string

No pizza can satisfy these requests. 

on a line by itself starting in column 1.

Sample Input 

+A+B+C+D-E-F-G-H; -A-B+C+D-E-F+G+H; -A+B-C+D-E+F-G+H; . +A+B+C+D; +E+F+F+H; +A+B-G; +O+J-F; +H+I+C; +P; +O+M+L; +M-L+P; . +A+B+C+D; +E+F+F+H; +A+B-G; +P-O; +O+J-F; +H+I+C; +P; +O; +O+M+L; -O-P; +M-L+P; . 

Sample Output 

Toppings: Toppings: CELP No pizza can satisfy these requests. 



Miguel A. Revilla
1998-03-10

所有可能。

一下目意思:每材料可放或不放,因此 2^16 ,只要符合任一人至少一的要求。

//0.464 s

#include <stdio.h>
int main() {
    char s[105];
    int i, j;
    while(1) {
        int person[105][2] = {}, n = 0;
        while(gets(s) && s[0] != '.') {
            for(i = 0; s[i] != ';'; i += 2) {
                if(s[i] == '+')
                    person[n][0] |= 1<<(s[i+1]-'A');
                else
                    person[n][1] |= 1<<(s[i+1]-'A');
            }
            n++;
        }
        if(n == 0)  break;
        int m = 1<<16;
        for(i = 0; i < m; i++) {
            for(j = 0; j < n; j++) {
                if(i&person[j][0])  continue;
                if((m-1-i)&person[j][1])  continue;
                break;
            }
            if(j == n) {
                printf("Toppings: ");
                for(j = 0; j < 16; j++)
                    if((i>>j)&1)
                        putchar(j+'A');
                puts("");
                break;
            }
        }
        if(i == m)
            puts("No pizza can satisfy these requests.");
    }
    return 0;
}

台: Morris
人(751) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA][搜索] 10582 - ASCII Labyrinth
此分上一篇:[UVA][并、交、周] 10969 - Sweet Dream

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86