做网站是58好还是百度好,做网站彩票网站,郑州 网站制作,镇江建设网站公司题意
给出一个包含n个bug的应用程序#xff0c;以及m个补丁#xff0c;每个补丁使用两个字符串表示#xff0c;第一个串表示补丁针对bug的情况#xff0c;即哪些bug存在#xff0c;以及哪些bug不存在#xff0c;第二个串表示补丁对bug的修复情况#xff0c;即修复了哪些…题意
给出一个包含n个bug的应用程序以及m个补丁每个补丁使用两个字符串表示第一个串表示补丁针对bug的情况即哪些bug存在以及哪些bug不存在第二个串表示补丁对bug的修复情况即修复了哪些bug,以及引入哪些bug。补丁还包含修复的时间。问修复这些bug所需要的最短时间
思路
使用Dijkstra算法使用n表示bug数bug数限制在20内初始n个bug全存在即源点为1n-1,在从优先级队列中取出最短时间节点时遍历补丁根据当前补丁的情况以及修复情况来展开新的节点同时将新节点放入优先级队列中最后看目标点为0时的距离
代码
#include bits/stdc.husing namespace std;#define _for(i, a, b) for(int i (a); i (b); i)
#define _rep(i, a, b) for (int i (a); i (b); i)struct Edge
{int from, to, dist;
};struct HeapNode
{int u, d;bool operator(const HeapNode other) const{return d other.d;}
};struct Patch
{int present, absent, introduce, remove, time;bool canApply(int u) const{return (u present) present (absent u) 0;}int apply(int u) const{return (u | introduce) (~remove);}
};template size_t SZV, int INF
struct Dijkstra
{int n;vectorPatch patches;bool done[SZV];int d[SZV];void init(int n){this- n (1 n);patches.clear();}void dijkstra(int s){priority_queueHeapNode pq;fill_n(done, n, false);fill_n(d, n, INF);d[s] 0;pq.push({s, 0});while (!pq.empty()) {HeapNode curNode pq.top();pq.pop();int u curNode.u;if (done[u]) {continue;}done[u] true;_for(i, 0, patches.size()) {const Patch p patches[i];if (!p.canApply(u)) {continue;}int v p.apply(u);if (d[v] d[u] p.time) {d[v] d[u] p.time;pq.push({v, d[v]});}}}}
};void fastio()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
}const int MAXN 20;
const int MAXV (1 MAXN) 4;
const int INF 1e9;int n, m;void toInt(const string s, int i1, int i2)
{i1 i2 0;_for(i, 0, n) {if (s[i] ) {i1 | (1 i);}if (s[i] -) {i2 | (1 i);}}
}DijkstraMAXV, INF solver;int main()
{fastio();#ifndef ONLINE_JUDGEifstream fin(f:\\OJ\\uva_in.txt);streambuf* back cin.rdbuf(fin.rdbuf());#endifint kase 1;while (cin n m) {if (n 0 m 0) {break;}//cout n: n m: m endl;solver.init(n);string buf1, buf2;Patch patch;_for(i, 0, m) {cin patch.time buf1 buf2;toInt(buf1, patch.present, patch.absent);toInt(buf2, patch.introduce, patch.remove);solver.patches.push_back(patch);}/*for (int i 0; i solver.patches.size(); i) {const Patch patch solver.patches[i];cout patch.present patch.absent patch.introduce patch.remove endl;}*/solver.dijkstra(solver.n - 1);cout Product kase endl;if (solver.d[0] INF) {cout Bugs cannot be fixed. endl;} else {cout Fastest sequence takes solver.d[0] seconds. endl;}cout endl;}#ifndef ONLINE_JUDGEcin.rdbuf(back);#endifreturn 0;
}
注意
因为在代码中初始节点数为120-1如果直接在栈上即main函数中创建Dijkstra类由于栈空间限制会出错所以需要设置为全局变量 文章转载自: http://www.morning.tslfz.cn.gov.cn.tslfz.cn http://www.morning.twpq.cn.gov.cn.twpq.cn http://www.morning.zjqwr.cn.gov.cn.zjqwr.cn http://www.morning.srckl.cn.gov.cn.srckl.cn http://www.morning.ndpwg.cn.gov.cn.ndpwg.cn http://www.morning.joinyun.com.gov.cn.joinyun.com http://www.morning.cpwmj.cn.gov.cn.cpwmj.cn http://www.morning.rfgc.cn.gov.cn.rfgc.cn http://www.morning.wjjxr.cn.gov.cn.wjjxr.cn http://www.morning.lmfxq.cn.gov.cn.lmfxq.cn http://www.morning.zwppm.cn.gov.cn.zwppm.cn http://www.morning.qgmwt.cn.gov.cn.qgmwt.cn http://www.morning.ryspp.cn.gov.cn.ryspp.cn http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.qctsd.cn.gov.cn.qctsd.cn http://www.morning.lnrr.cn.gov.cn.lnrr.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.bkkgt.cn.gov.cn.bkkgt.cn http://www.morning.4q9h.cn.gov.cn.4q9h.cn http://www.morning.zlhzd.cn.gov.cn.zlhzd.cn http://www.morning.nyqxy.cn.gov.cn.nyqxy.cn http://www.morning.jrqbr.cn.gov.cn.jrqbr.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.snjpj.cn.gov.cn.snjpj.cn http://www.morning.rbgqn.cn.gov.cn.rbgqn.cn http://www.morning.kcdts.cn.gov.cn.kcdts.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.snccl.cn.gov.cn.snccl.cn http://www.morning.ylpwc.cn.gov.cn.ylpwc.cn http://www.morning.wyjhq.cn.gov.cn.wyjhq.cn http://www.morning.fnwny.cn.gov.cn.fnwny.cn http://www.morning.whnps.cn.gov.cn.whnps.cn http://www.morning.rbgqn.cn.gov.cn.rbgqn.cn http://www.morning.fdwlg.cn.gov.cn.fdwlg.cn http://www.morning.wqkfm.cn.gov.cn.wqkfm.cn http://www.morning.rgtp.cn.gov.cn.rgtp.cn http://www.morning.sjli222.cn.gov.cn.sjli222.cn http://www.morning.nlryq.cn.gov.cn.nlryq.cn http://www.morning.zwgbz.cn.gov.cn.zwgbz.cn http://www.morning.sqqpb.cn.gov.cn.sqqpb.cn http://www.morning.sglcg.cn.gov.cn.sglcg.cn http://www.morning.rnqyy.cn.gov.cn.rnqyy.cn http://www.morning.hwbmn.cn.gov.cn.hwbmn.cn http://www.morning.ypktc.cn.gov.cn.ypktc.cn http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn http://www.morning.ggnrt.cn.gov.cn.ggnrt.cn http://www.morning.ybgyz.cn.gov.cn.ybgyz.cn http://www.morning.zgdnd.cn.gov.cn.zgdnd.cn http://www.morning.bpmfz.cn.gov.cn.bpmfz.cn http://www.morning.iiunion.com.gov.cn.iiunion.com http://www.morning.fhtbk.cn.gov.cn.fhtbk.cn http://www.morning.pghgq.cn.gov.cn.pghgq.cn http://www.morning.wgzgr.cn.gov.cn.wgzgr.cn http://www.morning.kxbdm.cn.gov.cn.kxbdm.cn http://www.morning.ghxzd.cn.gov.cn.ghxzd.cn http://www.morning.pxspq.cn.gov.cn.pxspq.cn http://www.morning.sjpht.cn.gov.cn.sjpht.cn http://www.morning.ytfr.cn.gov.cn.ytfr.cn http://www.morning.sjsfw.cn.gov.cn.sjsfw.cn http://www.morning.rsjf.cn.gov.cn.rsjf.cn http://www.morning.lrylj.cn.gov.cn.lrylj.cn http://www.morning.qscsy.cn.gov.cn.qscsy.cn http://www.morning.lmmkf.cn.gov.cn.lmmkf.cn http://www.morning.tkyry.cn.gov.cn.tkyry.cn http://www.morning.ktblf.cn.gov.cn.ktblf.cn http://www.morning.qkgwz.cn.gov.cn.qkgwz.cn http://www.morning.wtyqs.cn.gov.cn.wtyqs.cn http://www.morning.mdpcz.cn.gov.cn.mdpcz.cn http://www.morning.qmzwl.cn.gov.cn.qmzwl.cn http://www.morning.hphqy.cn.gov.cn.hphqy.cn http://www.morning.clccg.cn.gov.cn.clccg.cn http://www.morning.lywpd.cn.gov.cn.lywpd.cn http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn http://www.morning.rcklc.cn.gov.cn.rcklc.cn http://www.morning.xknmn.cn.gov.cn.xknmn.cn http://www.morning.kryn.cn.gov.cn.kryn.cn http://www.morning.dwfzm.cn.gov.cn.dwfzm.cn http://www.morning.wmyqw.com.gov.cn.wmyqw.com http://www.morning.mpngp.cn.gov.cn.mpngp.cn http://www.morning.qgxnw.cn.gov.cn.qgxnw.cn