POJ 1548 Robots

题目链接

题意:乍一看还以为是小白上那题dp,事实上不是,就是求一共几个机器人能够覆盖全部路径

思路:最小路径覆盖问题。一个点假设在还有一个点右下方,就建边。然后跑最小路径覆盖就可以

代码:

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std; const int N = 25 * 25; int x[N], y[N], cnt = 1;
vector<int> g[N]; bool judge(int i, int j) {
return x[j] >= x[i] && y[j] >= y[i];
} int left[N], vis[N]; bool dfs(int u) {
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (vis[v]) continue;
vis[v] = 1;
if (left[v] == -1 || dfs(left[v])) {
left[v] = u;
return true;
}
}
return false;
} int hungary() {
int ans = 0;
memset(left, -1, sizeof(left));
for (int i = 0; i < cnt; i++) {
memset(vis, 0, sizeof(vis));
if (dfs(i)) ans++;
}
return ans;
} int main() {
while (~scanf("%d%d", &x[0], &y[0])) {
if (x[0] == -1 && y[0] == -1) break;
while (~scanf("%d%d", &x[cnt], &y[cnt])) {
if (x[cnt] == 0 && y[cnt] == 0) break;
cnt++;
}
for (int i = 0; i < cnt; i++) {
g[i].clear();
for (int j = 0; j < i; j++) {
if (judge(i, j)) g[i].push_back(j);
if (judge(j, i)) g[j].push_back(i);
}
}
printf("%d\n", cnt - hungary());
cnt = 1;
}
return 0;
}

POJ 1548 Robots(最小路径覆盖)的更多相关文章

  1. POJ 3020 (二分图+最小路径覆盖)

    题目链接:http://poj.org/problem?id=3020 题目大意:读入一张地图.其中地图中圈圈代表可以布置卫星的空地.*号代表要覆盖的建筑物.一个卫星的覆盖范围是其周围上下左右四个点. ...

  2. K - Treasure Exploration - POJ 2594(最小路径覆盖+闭包传递)

    题意:给一个有向无环图,求出来最小路径覆盖,注意一个点可能会被多条路径重复 分析:因为有可能多条路径走一个点,可又能会造成匹配的不完全,所以先进行一次闭包传递(floyd),然后再用二分匹配的方法求出 ...

  3. Taxi Cab Scheme POJ - 2060 二分图最小路径覆盖

    Running a taxi station is not all that simple. Apart from the obvious demand for a centralised coord ...

  4. POJ 1422 DAG最小路径覆盖

    求无向图中能覆盖每个点的最小覆盖数 单独的点也算一条路径 这个还是可以扯到最大匹配数来,原因跟上面的最大独立集一样,如果某个二分图(注意不是DAG上的)的边是最大匹配边,那说明只要取两个端点只要一条边 ...

  5. poj 1548(最小路径覆盖)

    题目链接:http://poj.org/problem?id=1548 思路:最小路径覆盖是很容易想到的(本题就是求最小的路径条数覆盖所有的点),关键是如何建图,其实也不难想到,对于当前点,如果后面的 ...

  6. POJ 2594 传递闭包的最小路径覆盖

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 7171   Accepted: 2 ...

  7. poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)

    http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total ...

  8. POJ Treasure Exploration 【DAG交叉最小路径覆盖】

    传送门:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K To ...

  9. POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

    Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. Java获取URL链接的文件类型

    问题发生: Java从网络批量读取图片并保存至本网站服务器后再插入文章中 今天转入一篇文章 http://news.qq.com/a/20170605/045860.htm 发现图片未能成功上传 查看 ...

  2. tomcat使用不同jdk的解决方法

    1,修改bin文件夹下面的catalina.bat文件,把如下内容 rem ----- Execute The Requested Command -------------------------- ...

  3. Charles抓包https

    Charles抓包https 灰灰是只小贱狗 2018.05.08 10:46 字数 762 阅读 7800评论 3喜欢 3 抓取HTTPS请求包,对数据进行排查检验 1.安装Charles 2.电脑 ...

  4. Binary Search Tree 以及一道 LeetCode 题目

    一道LeetCode题目 今天刷一道LeetCode的题目,要求是这样的: Given a binary search tree and the lowest and highest boundari ...

  5. Orchard之生成新模板

    一:启用 Code Generation 进入后台, Modules –>  Developer Enable 之.   二:生成模版 首先,进入 Orchard 命令行 在 CMD 下到达解决 ...

  6. [转]Zend Studio中将tab转换为4个空格

    From : http://our2848884.blog.163.com/blog/static/14685483420129318619284/ 例子如下:  1 选中需要转换的区域   2 Ct ...

  7. NAT模式

    NAT NAT模式中,就是让虚拟机借助NAT(网络地址转换)功能,通过宿主机器所在的网络来访问公网. NAT模式中,虚拟机的网卡和物理网卡的网络,不在同一个网络,虚拟机的网卡,是在vmware提供的一 ...

  8. The "Out of socket memory" error

    The "Out of socket memory" error I recently did some work on some of our frontend machines ...

  9. 学 Win32 汇编[33] - 探讨 Win32 汇编的模块化编程

    我觉得所谓的模块化有两种: "假模块化" 和 "真模块化". 所谓 "假模块化" 就是通过 include 指令把 *.inc 或 *.as ...

  10. Android Eclipseproject开发中的常见调试问题(二)android.os.NetworkOnMainThreadException 异常的解决的方法

    android.os.NetworkOnMainThreadException 异常的解决的方法. 刚开是把HttpURLConnectionnection 打开连接这种方法放在UI线程里了,可能不是 ...