zoukankan      html  css  js  c++  java
  • uva-565-枚举

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

    用位枚举

    #include <stdio.h>
    #include<iostream>
    #include <string.h>
    #include<memory.h>
    using namespace std;
    const int N = 17;
    int yes[17] = { 0 };
    int no[17] = { 0 };
    const string out = "Toppings: ";
    int total = 0;
    int main()
    {
        char input2[100];
        while (gets(input2) != NULL)
        {
            if(input2[0] == '.')
            {
                int i = 0;
                for(i = 0; i < (1 << 16); i++)
                {
                    int k = 0;
                    for(; k < total; k++)
                    {
                        if((yes[k] & i) | (no[k] & (~i)))
                            continue;
                        else
                            break;
                    }
                    if(k == total)
                        break;
                }
                if(i == (1 << 16))
                {
                    cout << "No pizza can satisfy these requests." << endl;
                }
                else
                {
                    char ss[16];
                    memset(ss, 0, sizeof(ss));
                    int index = 0;
                    for(int k = 0; k < 16; k++)
                    {
                        if(i & (1 << k))
                            ss[index++] = k + 'A';
                    }
                    cout << out;
                    cout << ss << endl;
                }
                memset(yes, 0, sizeof(yes));
                memset(no, 0, sizeof(no));
                total = 0;
            }
            else
            {
                for(int i = 0;input2[i]!=';'; i=i+2)
                {
                    if(input2[i] == '+')
                    {
                        char cc = input2[i+1];
                        yes[total] = (yes[total]) | (1 << (cc - 'A'));
                    }
                    else
                    {
                        char cc = input2[i+1];
                        no[total] = (no[total]) | (1 << (cc - 'A'));
                    }
                }
                ++total;
            }
        }
        return 0;
    }
  • 相关阅读:
    Markdown学习
    二叉树的最近公共祖先
    javaCompiler简析
    自定义类加载器
    聚合和组合的区别
    拓扑排序
    C++ map和unordered_map
    静态文件加载路径
    文件上传
    jackson
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/8667336.html
Copyright © 2011-2022 走看看