uva658 - It's not a Bug, it's a Feature! 状态压缩+隐式图搜索+优先队列的dijkstra

生态学家都在用的MixSIAR:用R语言搞定稳定同位素混合模型(从数据整理到结果解读) 本文详细介绍了生态学家常用的MixSIAR工具,通过R语言实现稳定同位素混合模型分析,从数据整理到结果解读全流程。文章涵盖环境准备、模型构建、参数设置、运行诊断及可视化等关键步骤,帮助研究者科学分析河口鱼类食物来源,适用于生态学研究和湿地保护政策制定。 阅读详情

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

It is a curious fact that consumers buying a new software product generally donot 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= \{b_1, b_2, \dots, b_n\}$ in their software. And they have releasedm patches $p_1, p_2, \dots, p_m$. To apply patchpi to the software, the bugs $B^+_i \subseteq B$ have to be present in the software, and the bugs$B^-_i \subseteq B$ must be absent (of course$B^+_i \cap B^-_i = \emptyset$ holds). The patch then fixes the bugs$F^-_i \subseteq B$ (if they have been present) and introduces the new bugs$F^+_i \subseteq B$ (where, again,$F^-_i \cap B^-_i = \emptyset$).

Tinyware's problem is a simple one. Given the original version of their software, which contains all the bugs inB, it is possible to apply a sequence of patches to the software which results in a bug- free version of the software? And if so, assuming that every patch takes a certain time to apply, how long does the fastest sequence take?

Input 

The input contains several product descriptions. Each description starts with a line containing two integersn and m, the number of bugs and patches, respectively. These values satisfy$1 \le n \le 20$ and$1 \le m \le 100$. This is followed bym lines describing the m patches in order. Each line contains an integer, the time in seconds it takes to apply the patch, and two strings ofn characters each.

The first of these strings describes the bugs that have to be present or absent before the patch can be applied. Thei-th position of that string is a ``+'' if bug bi has to be present, a ``-'' if bugbi has to be absent, and a `` 0'' if it doesn't matter whether the bug is present or not.

The second string describes which bugs are fixed and introduced by the patch. Thei-th position of that string is a ``+'' if bug bi is introduced by the patch, a ``-'' if bugbi is removed by the patch (if it was present), and a ``0'' if bugbi is not affected by the patch (if it was present before, it still is, if it wasn't, is still isn't).

The input is terminated by a description starting with n = m = 0. This test case should not be processed.

Output 

For each product description first output the number of the product. Then output whether there is a sequence of patches that removes all bugs from a product that has alln bugs. Note that in such a sequence a patch may be used multiple times. If there is such a sequence, output the time taken by the fastest sequence in the format shown in the sample output. If there is no such sequence, output ``Bugs cannot be fixed.''.

Print a blank line after each test case.

Sample Input 

3 3
1 000 00-
1 00- 0-+
2 0-- -++
4 1
7 0-0+ ----
0 0

Sample Output 

Product 1
Fastest sequence takes 8 seconds.

Product 2
Bugs cannot be fixed.

  首先。。这个题肯定不是我自己想出来的。。太高端了,光题目意思就看了好久。参考了别人的思路。

  有N个bug和M个补丁,接下来M行给出这个补丁需要的时间,第一个字符串a是这个补丁只能在这种状态下才能使用,a[i]=='+'就是第i个漏洞必须存在,a[i]=='-'是第i个漏洞不能存在,a[i]==‘0’不要求。第二个串b,b[i]=='+'是使用这个补丁后第i个bug产生,b[i]=='-'是使用这个补丁后第i个bug被修复,b[i]=='0'还保持原来的状态不变。问最少需要多少时间修复所有的漏洞。

  主要思想是把每种状态用2进制表示,建图,起点为11111(n个,也就是2^n-1),用dijkstra算出终点状态(0)的最短路。。这题还必须要用优先队列的dijkstra,要不会超时。。。

  建图的时候dfs每种补丁能修复的所有状态,把这个能修复的状态和修复后的状态建立连接。因为要用优先队列的dijkstra,就要用到pair,定义结构体有y和t。定义的vector为结构体的类型的数组。

  优先队列的dijkstra方法:定义pii的优先队列priority_queue<pii,vector<pii>,greater<pii> >q; 先把起点和0加到优先队列里。当队列非空,每次取出d值最小的(如果不定义优先队列的比较函数,pair时默认先比较第一维),然后删除,也就是pii cur=q.top(),q.pop()。这时x=cur.second就是要加入的点了,如果x没有访问过,把x标记访问,再把跟x连接的点(有v[x].size()个)都更新重新加入队列(就算一个点被加入多次也没事,先取出的也是d值最小的那个)。最后d[0]就是答案。

  优先队列的dijkstra算法复杂度是O(MlogN),因为会把每条边算一遍,并且优先队列操作复杂度是O(logN)。


#include<cstring>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
int N,M,T,P;
int vis[1200000],d[1200000];
char a[25],b[25];
struct st{
    int y,t;
};
vector<st> v[1200000];
void add(int fa,int son){
    st cur;
    cur.y=son;
    cur.t=T;
    v[fa].push_back(cur);
}
void DFS(int cur,int *s){
    if(cur>=N){
        int fa=0,son=0,k;
        for(int i=0;i<N;i++){
            if(b[i]=='0') k=s[i];
            if(b[i]=='+') k=1;
            if(b[i]=='-') k=0;
            son=(son<<1)+k;
            fa=(fa<<1)+s[i];
        }
        add(fa,son);
        return;
    }
    if(a[cur]=='0'){
        s[cur]=0;
        DFS(cur+1,s);
        s[cur]=1;
        DFS(cur+1,s);
    }
    if(a[cur]=='+'){
        s[cur]=1;
        DFS(cur+1,s);
    }
    if(a[cur]=='-'){
        s[cur]=0;
        DFS(cur+1,s);
    }
}
void dijkstra(){
    priority_queue<pii,vector<pii>,greater<pii> >q;
    memset(vis,0,sizeof(vis));
    memset(d,INF,sizeof(d));
    d[P-1]=0;
    q.push(make_pair(d[P-1],P-1));
    while(!q.empty()){
        pii cur=q.top();
        q.pop();
        int x=cur.second;
        if(vis[x]) continue;
        vis[x]=1;
        int L=v[x].size();
        for(int i=0;i<L;i++){
            int y=v[x][i].y;
            if(d[x]+v[x][i].t<d[y]){
                d[y]=d[x]+v[x][i].t;
                q.push(make_pair(d[y],y));
            }
        }
    }
    if(d[0]==INF) printf("Bugs cannot be fixed.\n\n");
    else printf("Fastest sequence takes %d seconds.\n\n",d[0]);
}
int main(){
    freopen("in.txt","r",stdin);
    int cas=0;
    while(scanf("%d%d",&N,&M),N||M){
        P=1<<N;
        for(int i=0;i<P;i++) v[i].clear();
        while(M--){
            scanf("%d%s%s",&T,a,b);
            int c[25];
            memset(c,0,sizeof(c));
            DFS(0,c);
        }
        printf("Product %d\n",++cas);
        dijkstra();
    }
    return 0;
}



MTK AWB 色温曲线的进一步猜想 平均距离来判断是否对该色温下白平衡进行全部收白处理,还是保留一些光源的本身的颜色。比如占据图像一大半左右的纯色背景,纵坐标值相对横坐标的距离应该会比较大,大于一般场景下的正常白点分布。反之,位于Plank_curve下方位置的点具有偏洋红色的倾向。此时拟合各个色温下的白点,拟合曲线大致是以X= 0.85)平行于横轴的一条直线。对原始坐标系中的点取对数后的Log坐标系空间。此时拟合各个色温下的白点,拟合曲线大致呈现的是一条直线。,可以认为是各种色温下白点分布所呈现的走向。的算法利用某个色温点的偏离。 阅读详情

相关推荐

别再瞎调了!STM32 Systick延时函数避坑指南(正点原子、野火、慧净代码对比)

本文深入解析STM32 Systick延时函数的实现差异与优化策略,对比正点原子、野火、慧净等主流方案的优缺点。针对us和ms级延时精度问题,提供避坑指南和高级优化技巧,帮助开发者根据项目需求选择最佳方案,提升嵌入式系统的定时控制精度。

weixin_28717807的博客 340

uva_658_It's not a Bug, it's a Feature!(最短路)

题意:补丁在修补bug时,有时候会引入新的bug。假定有n(n<=20)个潜在bug和m(m<=100)个补丁,每个补丁用两个长度为n的字符串表示,其中字符串的每个位置表示一个bug。第一个串表示打补丁前的状态(“-”表示该bug必须不存在,“+”表示必须存在,“0”表示无所谓),第二个串表示打补丁后的状态(“-”表示不存在,“+”表示存在,“0”表示不变)。每个补丁都有一个执行时间,你的任务是用最少的时间把一个所有bug都存在的软件通过打补丁的方式变得没有bug。一个补丁可以打多次。

一点也不二 1880

硬件工程师必看:5种ESD保护电路设计实战解析(附电路图)

本文为硬件工程师深度解析5种实战ESD保护电路设计,涵盖TVS二极管、专用保护芯片、片上防护及高速射频场景方案。通过具体电路图,详解工作原理、选型要点及PCB布局黄金法则,重点强调ESD防护设计中的能量泄放路径管理与低阻抗实现,助力提升产品可靠性。

xk7n92h3p5m的博客 637

UVA 658 - It's not a Bug, it's a Feature!(dijkstra+优先队列)

题意: 某个软件有n个漏洞m的补丁,而每个补丁修复漏洞有前提条件,即有些漏洞必须存在或不存在,每个补丁的修复时间各不相同,现在有n个漏洞,让你求出把这n个漏洞全部修复所花的最少时间。 解析: 这个题目可以转化为最短路的模型来求解。由n个1或0来表示bug,我们很容易联想要二进制和十进制的转化,对于当前的bug状态,我们可以转化为1个十进制来表示,那么一开始的状态显然就是2^n-1,目标状态就

小G的ACM之路 893

如何在Tagetik系统中抽取处理SAP系统财务数据

如何在Tagetik系统中抽取处理不同核算系统财务数据:以SAP为例,简单讲一下Tagetik对接SAP数据的基本情况

2201_75401663的博客 577

CentOS 7 离线升级 OpenSSH 9.9p2 保姆级教程(含依赖包下载与常见报错解决)

本文提供了一份详尽的CentOS 7系统离线升级OpenSSH至9.9p2版本的完整教程。针对无外网环境,重点讲解了依赖包(尤其是OpenSSL 3.x)的离线下载与编译部署,并深入解决了编译过程中常见的“libcrypto.so缺失”等动态库链接错误。教程涵盖从环境准备、源码编译、服务配置到系统集成的全流程,最后还提供了关键的回滚方案与应急预案,是运维人员在内网环境中进行安全加固的实用指南。

weixin_29248313的博客 323

(beginer) 最短路 UVA 658 It\'s not a Bug, it\'s a Feature!

It's not a Bug, it's a Feature!  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 w

We Can 708

AUTOSAR BswM配置实战:手把手教你用Vector Davinci Configurator搭建第一个模式管理规则

本文详细介绍了如何使用Vector Davinci Configurator工具配置AUTOSAR BswM模块,实现车身控制ECU的模式管理规则。通过实战案例,从环境准备、核心概念梳理到具体配置步骤,包括ModeRequestPort、ModeCondition、Logical Expression和Rules的构建,帮助工程师快速掌握BswM配置技巧,提升汽车电子软件开发效率。

weixin_28678831的博客 351

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

题解:这折磨人的题目…补丁在修正BUG时,有时也会引入新的BUG,假定有n(n<=20)个潜在BUG,和m(m<=100)个补丁,每个补丁用两个长度为n的字符串表示,其中字符串的每个位置表示一个bug,第一个串表示打补丁之前的状态(“-”表示该BUG必须不存在,“+”表示该补丁必须存在,0表示无所谓),第二串表示打补丁之后的状态(”-“表示不存在,“+”表示存在,0表示不变)。每个补丁有一定的执行时

围巾的ACM博客 1114

大疆OcuSync系统背后的黑科技:跳频扩频技术如何让你的无人机飞得更稳

本文深入解析了大疆OcuSync系统如何运用跳频扩频技术等先进无线通信方案,显著提升无人机在复杂环境下的飞行稳定性。系统通过跳频扩频与直接序列扩频技术协同工作,结合双频智能切换与多天线MIMO,有效对抗信号干扰与多径效应,确保控制指令与高清图传的可靠、低延迟传输,为用户带来更安心、更流畅的飞行体验。

ol7890123的博客 627

RK3588内核崩溃日志捕获:pstore与ramoops的实战配置指南

本文详细介绍了在RK3588嵌入式设备上配置pstore与ramoops以捕获内核崩溃日志的实战指南。通过内核配置调整、设备树设置及高级调试技巧,帮助开发者有效定位系统崩溃原因,特别适合户外智能设备等无法长期连接调试器的场景。文章还提供了生产环境优化建议,确保日志捕获的可靠性与安全性。

weixin_29189363的博客 405

UVA 658 It's not a Bug, it's a Feature! (最短路,经典)

题意:有n个bug,有m个补丁,每个补丁有一定的要求(比如某个bug必须存在,某个必须不存在,某些无所谓等等),打完出来后bug还可能变多了呢。但是打补丁是需要时间的,每个补丁耗时不同,那么问题来了:要打多久才能无bug?(同1补丁可重复打) 分析:   n<=20,那么用位来表示bug的话有220=100万多一点。不用建图了,图实在太大了,用位图又不好玩。那么直接用隐...

weixin_30588729的博客 123

安全监控:人员行为分析_(2).人员行为分析基础理论

人员行为分析是指利用计算机视觉技术对视频中的人类行为进行实时或离线检测、识别和理解的过程。视频采集:通过摄像头等设备获取视频数据。视频预处理:对视频数据进行噪声过滤、图像增强等处理,以便后续分析。特征提取:从视频中提取出与人员行为相关的特征,如人体姿势、动作轨迹等。行为识别:利用机器学习或深度学习模型对提取的特征进行分类,识别出具体的人员行为。行为理解:对识别出的行为进行进一步分析,理解其背后的意图或状态。在人员行为分析中,常用的公开数据集包括UCF101、HMDB51、ActivityNet等。

zhubeibei168的博客 1344

Dinic+当前弧优化

Dinic算法是不停用BFS构造层次图,然后

7141

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Dijkstra 求最短路 最大流

原来Dijkstra算法不光只能求最短路问题,还能求最大流问题~~~求最短路 最大流" title="Dijkstra 求最短路 最大流"> 最短路问题时,Dijkstra算法的基本思想:   邻接矩阵w[x][y]保存x和y间的距离(别的设为INF,表示不连通,设为-1也行,后来更新加一个if(w[x][y]>=0)),数组d保存通过已经确定的点从起点到每个点的最短路。初始化d[0]=0,

1847

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

网络流 最大流 Edmonds-Karp算法

Edmonds-Karp算法,复杂度O(VE^2)。思想就是找增广路,不断增加流量。在残量(每条边上流量和容量的差)图上找一条每个边权值都为正的路(可以通过BFS,比DFS效率高),这些边权值里的最小值就是这条路可以增加的流量,然后在这条路径上更新流量。再重复找这样的路更新流量,直到找不到这样的路了就说明流量不能再增加了,当前的流就已经是最大流。   同时最大流也是最小割(权值和最小的割集)。设

1842

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Bellman_Ford和Spfa两种方法判断负环

Bellman_Ford是通过N-1次循环求出每个点到原点的最短路的,每次循环遍历所有的边,如果能更新就更新。前面说过为什么N-1次就行(若一个点到起点的最短路需要经过N个点,包括他自己,那么第N次循环就能确定他的最短路)。   最短路一定是不含环的,如果存在负环就根本不存在最短路了。所以这个方法可以用来判断是否有负环,如果循环了N-1次后还能进行松弛操作,说明有负环。Bellman_Ford的

1712

hdu5294 Tricks Device 最短路+最小割 多校联合第一场

Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 66    Accepted Submission(s): 14 Problem Description Innocent Wu follows

1563

uva1416 - Warfare And Logistics 最短路树优化

The army of United Nations launched a new wave of air strikes on terroristforces. The objective of the mission is to reduce enemy's logistical mobility. Each airstrike will destroy a path and therefor

1002

uva1324 - Bring Them There 网络流

By the year 3141, the human civilization has spread all over the galaxy. The special hypertunnels are usedto travel from one star system to another. To use the hypertunnel, you fly to a special locati

816

uva10806 - Dijkstra, Dijkstra. 最小费用流 求两条路权值之和最小

最小费用流是每次在残量图中求出起点到终点的最短路,然后再找出最短路上权值最小的一个边作为增广流量进行增广,更新流量,加上费用(最短路*增广流量)。找最短路用的不带链接表的spfa算法。因为每次增广后都是新流量下的最小费用流,所以最后就是最大流的最小费用。   如果是无向图、有平行边和反向边就比较麻烦了。。在有向图,没有平行边和反向边的情况下,设cap[v][u]=0,cost[v][u]=-co

781

uva10269 - Adventure of Super Mario floyd+dp+spfa

Problem A Adventure of Super Mario Input: Standard Input Output: Standard Output After rescuing the beautiful princess, Super Mario needs to find a way home -- with the princess of course :-

771

uva1306 - The K-League 网络流

Supporters for the professional soccer clubs participating in the K-League, formerly the Korea Professional Soccer League, hold orderly and organized cheering, as did the Red Devils, the official supp

769

匈牙利算法 二分图

这几个图和定义转自https://www.byvoid.com/blog/hungary/  未盖点:设Vi是图G的一个顶点,如果Vi 不与任意一条属于匹配M的边相关联,就称Vi 是一个未盖点。 交错路:设P是图G的一条路,如果P的任意两条相邻的边一定是一条属于M而另一条不属于M,就称P是一条交错路。 可增广路:两个端点都是未盖点的交错路叫做可增广路。     匈牙

737

sdut2414 An interesting game 费用流

An interesting game Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Xiao Ming recently designs a little game, in front of player there are N small hillsides put in order, now Xia

711

uva11354 - Bond 最小瓶颈路+LCA

Once again, James Bond is on his way tosaving the world. Bond's latest mission requires him to travel between severalpairs of cities in a certain country.   The country has N cities(numbered by 1, 2

710
上一篇: uva306 - Cipher 置换群
下一篇: Bellman_Ford和Spfa两种方法判断负环
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值