日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HNOI2013】消毒

發(fā)布時(shí)間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HNOI2013】消毒 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題面

題解

當(dāng)只有二維時(shí),就是一個(gè)二分圖匹配的板子題

三維的時(shí)候就很好做了,暴力枚舉一維的情況,因?yàn)?span id="ozvdkddzhkzd" class="math inline">\(\min(x,y,z) = \sqrt{5000} < 18\),于是時(shí)間復(fù)雜度有保證

代碼

#include<cstdio> #include<cstring> #include<cctype> #include<algorithm> #define RG register #define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout); #define clear(x, y) memset(x, y, sizeof(x))inline int read() {int data = 0, w = 1; char ch = getchar();while(ch != '-' && (!isdigit(ch))) ch = getchar();if(ch == '-') w = -1, ch = getchar();while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();return data * w; }const int maxn(5010); struct edge { int next, to; } e[maxn]; int head[maxn], e_num, a, b, c, Min, pos[4][maxn], vis[maxn], match[maxn], clean[maxn], ans, cnt, T;inline void add_edge(int from, int to) { e[++e_num] = (edge) {head[from], to}; head[from] = e_num; } bool dfs(int x) {for(RG int i = head[x]; i; i = e[i].next){int to = e[i].to; if(vis[to]) continue; vis[to] = true;if(!match[to] || dfs(match[to])) return match[to] = x, true;}return false; }inline void Doit(int x) {using std::fill; e_num = 0;fill(head + 1, head + b + 1, 0);fill(match + 1, match + c + 1, 0);fill(clean + 1, clean + a + 1, 1);int res = 0;for(RG int i = 0; i < a; i++)if(x & (1 << i)) clean[i + 1] = 0, ++res;for(RG int i = 1; i <= cnt; i++)if(clean[pos[1][i]]) add_edge(pos[2][i], pos[3][i]);for(RG int i = 1; i <= b; i++){fill(vis + 1, vis + c + 1, 0);if(dfs(i)) ++res;}ans = std::min(ans, res); }int main() {T = read();while(T--){cnt = 0; ans = 0x3f3f3f3f;a = read(); b = read(); c = read(); Min = std::min(std::min(a, b), c);for(RG int i = 1, x; i <= a; i++)for(RG int j = 1; j <= b; j++)for(RG int k = 1; k <= c; k++)if((x = read())) ++cnt, pos[1][cnt] = i, pos[2][cnt] = j, pos[3][cnt] = k;using std::swap;if(Min == b) swap(a, b), swap(pos[1], pos[2]);if(Min == c) swap(a, c), swap(pos[1], pos[3]);for(RG int i = 0; i < (1 << a); i++) Doit(i);printf("%d\n", ans);}return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/cj-xxz/p/10396342.html

總結(jié)

以上是生活随笔為你收集整理的【HNOI2013】消毒的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。