题面

题解

当只有二维时,就是一个二分图匹配的板子题

三维的时候就很好做了,暴力枚举一维的情况,因为\(\min(x,y,z) = \sqrt{5000} < 18\),于是时间复杂度有保证

代码

#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;
}

【HNOI2013】消毒的更多相关文章

  1. [BZOJ3140][HNOI2013]消毒(二分图最小点覆盖)

    3140: [Hnoi2013]消毒 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1621  Solved: 676[Submit][Status] ...

  2. bzoj 3140: [Hnoi2013]消毒

    3140: [Hnoi2013]消毒 Description 最近在生物实验室工作的小T遇到了大麻烦. 由于实验室最近升级的缘故,他的分格实验皿是一个长方体,其尺寸为a*b*c,a.b.c 均为正整数 ...

  3. P3231 [HNOI2013]消毒

    P3231 [HNOI2013]消毒 二维覆盖我们已经很熟悉了 扩展到三维,枚举其中较小的一维,这里定义为$a$ 以$a$为关键字状压,$1$表示该面全选 剩下的面和二维覆盖一样二分图匹配 如果还没接 ...

  4. 3140:[HNOI2013]消毒 - BZOJ

    题目描述 Description 最近在生物实验室工作的小 T 遇到了大麻烦. 由于实验室最近升级的缘故,他的分格实验皿是一个长方体,其尺寸为 a*b*c,a.b.c均为正整数.为了实验的方便,它被划 ...

  5. bzoj3140: [Hnoi2013]消毒

    Description 最近在生物实验室工作的小T遇到了大麻烦. 由于实验室最近升级的缘故,他的分格实验皿是一个长方体,其尺寸为a*b*c,a.b.c 均为正整数.为了实验的方便,它被划分为a*b*c ...

  6. 【刷题】BZOJ 3140 [Hnoi2013]消毒

    Description 最近在生物实验室工作的小T遇到了大麻烦. 由于实验室最近升级的缘故,他的分格实验皿是一个长方体,其尺寸为abc,a.b.c 均为正整数.为了实验的方便,它被划分为abc个单位立 ...

  7. BZOJ3140:[HNOI2013]消毒——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=3140 https://www.luogu.org/problemnew/show/P3231 最近在 ...

  8. bzoj3140: [Hnoi2013]消毒(二分图)

    题目描述 最近在生物实验室工作的小T遇到了大麻烦. 由于实验室最近升级的缘故,他的分格实验皿是一个长方体,其尺寸为a*b*c,a.b.c 均为正整数.为了实验的方便,它被划分为a*b*c个单位立方体区 ...

  9. [luogu3231 HNOI2013] 消毒 (二分图最小点覆盖)

    传送门 Description 最近在生物实验室工作的小T遇到了大麻烦. 由于实验室最近升级的缘故,他的分格实验皿是一个长方体,其尺寸为abc,a.b.c 均为正整数.为了实验的方便,它被划分为abc ...

  10. [HNOI2013]消毒

    题目大意: 网址:https://www.luogu.org/problemnew/show/3231 大意:a×b×c的三维空间里有a×b×c个点(x,y,z),其中有些点需要被消除. 消除的方法为 ...

随机推荐

  1. Sql语法高级应用之三:存储过程

    一.存储过程概述 SQL Server中的存储过程是使用T_SQL编写的代码段.它的目的在于能够方便的从系统表中查询信息,或者完成与更新数据库表相关的管理任务和其他的系统管理任务.T_SQL语句是SQ ...

  2. VisualSVN Server迁移的方法

    VisualSVN Server迁移涉及到两种情况: 第一种情况:VisualSVN Server没有更换电脑或者服务器,只是修改Server name. 第二种情况:当VisualSVN Serve ...

  3. RHEL7: How to configure a rc-local service

    问题: linux7 /etc/rc.local 不生效: [root@bogon mysql3306]# uname -aLinux bogon 3.10.0-862.el7.x86_64 #1 S ...

  4. swift版的StringAttribute

    swift版的StringAttribute 效果 源码 https://github.com/YouXianMing/Swift-StringAttribute // // StringAttrib ...

  5. 使用YXHUD

    使用YXHUD 这是本人自己设计的一个类,但功能很不完善,先看看效果: 源码: YXHUD.h 与 YXHUD.m // // YXHUD.h // UILabel // // Created by ...

  6. zabbix 监控wind登录状态

    参考博文:http://blog.51cto.com/qicheng0211/1694583 需求:监控win 2008 的用户登录状态,无论用户登录成功与否都要告警(也可以刷选指定用户.指定时间内) ...

  7. python3 实现细胞自动机

    废话不多说,先直接上效果图: “滑翔者”:每4个回合“它”会向右下角走一格.虽然细胞早就是不同的细胞了,但它能保持原本的形态. "脉冲星":它的周期为3,看起来像一颗周期爆发的星星 ...

  8. [装]JMX监控Hadoop

    http://chenjc-it.iteye.com/blog/1539746 实验成功!

  9. 1854. [SCOI2010]游戏【二分图】

    Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性 ...

  10. 搭建高可用mysql系列(1)-- Percona XtraDB Cluster介绍

    Percona XtraDB Cluster (下文简称PXC)是一个开源的mysql 高可用解决方案.它将Percona Server和Percona XtraBackup与Galera库集成在一起 ...