UVa658 It's not a Bug, it's a Feature!

177 篇文章 1 订阅
137 篇文章 0 订阅

It is a curious fact that consumers buying a new software product
generally do not expect the software to be bug-free. Can you imagine
buying a car whose steering wheel only turns to the right? Or a
CD-player that plays only CDs with country music on them? Probably
not. But for software systems it seems to be acceptable if they do not
perform as they should do. In fact, many software companies have
adopted the habit of sending out patches to fix bugs every few weeks
after a new product is released (and even charging money for the
patches). Tinyware Inc. is one of those companies. After releasing a
new word processing software this summer, they have been producing
patches ever since. Only this weekend they have realized a big problem
with the patches they released. While all patches fix some bugs, they
often rely on other bugs to be present to be installed. This happens
because to fix one bug, the patches exploit the special behavior of
the program due to another bug. More formally, the situation looks
like this. Tinyware has found a total of n bugs B
= f b 1 ; b 2 ; : : : ; b n g in their software. And they have released m patches p 1 ; p 2 ; : : : ; p m . To apply patch p i to the
software, the bugs B
+ i B have to be present in the software, and the bugs B

二进制压缩保存状态和补丁,然后用类似堆优化dijkstra/A*+判重【我也不知道算啥】的方法扩展。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int n,m,w[110],dis[5000010];
unsigned int a[110],b[110],c[110],d[110];
void init()
{
    int i,j;
    char s[110];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    memset(d,0,sizeof(d));
    for (i=1;i<=m;i++)
    {
        scanf("%d",&w[i]);
        scanf("%s",s);
        for (j=0;j<n;j++)
          if (s[j]!='0')
          {
            a[i]^=1<<j;
            if (s[j]=='+')
              b[i]^=1<<j;
          }
        scanf("%s",s);
        for (j=0;j<n;j++)
          if (s[j]!='0')
          {
            if (s[j]=='+')
              d[i]^=1<<j;
          }
          else
            c[i]^=1<<j;
    }
}
int solve()
{
    int j;
    unsigned int u,v,x;
    pair<int,int> tem;
    priority_queue<pair<int,int> >q;
    q.push(make_pair(0,(1<<n)-1));
    memset(dis,0x3f,sizeof(dis));
    dis[(1<<n)-1]=0;
    while (!q.empty())
    {
        tem=q.top();
        u=tem.second;
        x=-tem.first;
        q.pop();
        if (u==0) return x;
        for (j=1;j<=m;j++)
          if (((u&a[j])^b[j])==0)
          {
            v=(u&c[j])|d[j];
            if (x+w[j]<dis[v])
            {
                dis[v]=x+w[j];
                q.push(make_pair(-dis[v],v));
            }
          }
    }
    return -1;
}
int main()
{
    int K=0,x;
    while (scanf("%d%d",&n,&m)&&n)
    {
        printf("Product %d\n",++K);
        init();
        if ((x=solve())!=-1) printf("Fastest sequence takes %d seconds.\n",x);
        else printf("Bugs cannot be fixed.\n");
        printf("\n");
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值