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. .NET:如何并行的从集合中返还元素?

    实现代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...

  2. Android之代码创建布局

    大概描述一下效果:最外层是一个 RelativeLayout 里面有自定义个LinearLayout,每个LinearLayout有两个TextView.that's it !!! private v ...

  3. Android性能优化工具之Systrace

    本文大部分内容来自:http://www.androidperformance.com/android-performance-tools-systrace-1.html?utm_source=tui ...

  4. 诺基亚S40手机联系人导入安卓手机

    电话号码较少的话比较简单,拷贝到SIM卡中通过SIM卡中转,只是一般SIM卡只能存储200个左右,联系人比较多的情况就麻烦一点,今天帮导师把诺基亚5220中的800个电话转到三星S4中,综合下来还是使 ...

  5. Android 应用程序之间内容分享详解(二)

    转载请注明出处:http://blog.csdn.net/xiaanming/article/details/9428613 Android 应用程序之间内容分享详解(一) 之前给大家分享了你开发的应 ...

  6. 【总结】关于MediaPlayer中的getCurrentPosition()和seekTo(int)的总结

    在使用音频时,需要用到MediaPlayer,除了一些基础的方法之外,比较难掌握的就是设计播放点的调转的地方,进过反复调试,我最终找到一个可以让getCurrentPosition()和seekTo( ...

  7. File targeting 'AMD64' is not compatible with the project's target platform 'x86' 解决方法

     我在使用vs2010制作64位安装包时出现了以下问题: File targeting 'AMD64' is not compatible with the project's target plat ...

  8. Unique Binary Search Trees leetcode java

    题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For e ...

  9. 字符串 CSV解析 表格 逗号分隔值 通讯录 电话簿 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  10. 基于Bootstrap+jQuery.validate Form表单验证实践

    基于Bootstrap jQuery.validate Form表单验证实践 项目结构 :     github 上源码地址:https://github.com/starzou/front-end- ...