poj2594(二分圖,最小路徑覆蓋變形)

Treasure Exploration
Time Limit:?6000MS?Memory Limit:?65536K
Total Submissions:?7611?Accepted:?3126

Description

Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploration? Have you ever explored treasure? If you never have such experiences, you would never know what fun treasure exploring brings to you.?
Recently, a company named EUC (Exploring the Unknown Company) plan to explore an unknown place on Mars, which is considered full of treasure. For fast development of technology and bad environment for human beings, EUC sends some robots to explore the treasure.?
To make it easy, we use a graph, which is formed by N points (these N points are numbered from 1 to N), to represent the places to be explored. And some points are connected by one-way road, which means that, through the road, a robot can only move from one end to the other end, but cannot move back. For some unknown reasons, there is no circle in this graph. The robots can be sent to any point from Earth by rockets. After landing, the robot can visit some points through the roads, and it can choose some points, which are on its roads, to explore. You should notice that the roads of two different robots may contain some same point.?
For financial reason, EUC wants to use minimal number of robots to explore all the points on Mars.?
As an ICPCer, who has excellent programming skill, can your help EUC?

Input

The input will consist of several test cases. For each test case, two integers N (1 <= N <= 500) and M (0 <= M <= 5000) are given in the first line, indicating the number of points and the number of one-way roads in the graph respectively. Each of the following M lines contains two different integers A and B, indicating there is a one-way from A to B (0 < A, B <= N). The input is terminated by a single line with two zeros.

Output

For each test of the input, print a line containing the least robots needed.

Sample Input

1 0
2 1
1 2
2 0
0 0

Sample Output

1
1
2

題意:有很多機器人和1個圖,每個機器人從該圖的一個點出發,然后現在要求機器人走遍所有的點,求最小的機器人的數量。(2個機器人可以從不同方向走過同一點)。

思路:顯然相當于求最路徑覆蓋嘛,只不過就是最小路徑覆蓋是每個點不能被走兩次的,而現在可以走兩次了,所以想一個辦法就是把本身不能走的點連起來,比如一個機器人能從a->b->c,可是現在b已經被另一個機器人走過了,最短路徑覆蓋又不能讓一個點被兩個人走,可是該機器人必須從a->c才是最優解,所有用floyd將所有點有聯系的都連接起來,這樣子仍然是原來的最小路徑覆蓋的問題了。


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;
const int N=555;
bool tu[N][N];
int from[N];///記錄右邊的點如果配對好了它來自哪里
bool use[N];///記錄右邊的點是否已經完成了配對
int color[N];
int n,m;
bool dfs(int x)
{for(int i=1; i<=m; i++) ///m是右邊,所以這里上界是mif(!use[i]&&tu[x][i]){use[i]=1;if(from[i]==-1||dfs(from[i])){from[i]=x;return 1;}}return 0;
}
int hungary()
{int tot=0;memset(from,-1,sizeof(from));for(int i=1; i<=n; i++) ///n是左邊,所以這里上界是n{memset(use,0,sizeof(use));if(dfs(i))tot++;}return tot;
}
int main()
{int k;while(cin>>n>>k&&n+k){m=n;memset(tu,0,sizeof(tu));while(k--){int a,b;cin>>a>>b;tu[a][b]=1;}for(int k=1; k<=n; k++)for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)if(tu[i][k]&&tu[k][j])tu[i][j]=1;printf("%d\n",n-hungary());}return 0;
}


轉載于:https://www.cnblogs.com/martinue/p/5490459.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/255805.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/255805.shtml
英文地址,請注明出處:http://en.pswp.cn/news/255805.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【機器視覺】——相機鏡頭篇

目錄 一、相關概念 1、相機 2、鏡頭 二、相關參數 1、相機參數 1)芯片尺寸

閉包(計算機科學)

在計算機科學中&#xff0c;閉包&#xff08;Closure&#xff09;又稱詞法閉包或函數閉包。是引用了自由變量的函數。這個被引用的自由變量將會和函數在一起。即使離開了創建它的環境也不例外。所以另一種關于閉包的說法&#xff1a;由函數和其引用相關的環境構成的實體。閉包在…

C語言小機器人

[cpp] view plaincopyprint? # include <stdio.h> # include <stdlib.h> # define MAXSTR 200 # define REBOT "小C說: " # define YOUR "您 說: " # define EXIT "-e\n" # define NOREPLY "我不知道你說什么呢…

分享12306搶票心得-終極秒殺思路篇

12306搶票的關鍵拼的就是整點出票的速度&#xff0c;快的幾秒鐘&#xff0c;慢的幾分鐘&#xff0c;本文提供終極搶票攻略&#xff0c;通過多線程掃描上萬個CDN&#xff0c;來大幅度提升出票速度。準備一&#xff1a;需要了解CDN和切站的機制&#xff0c;請參考&#xff1a;分享…

JVM內幕:Java虛擬機詳解

為什么80%的碼農都做不了架構師&#xff1f;>>> 這篇文章解釋了Java 虛擬機&#xff08;JVM&#xff09;的內部架構。下圖顯示了遵守 Java SE 7 規范的典型的 JVM 核心內部組件。 上圖顯示的組件分兩個章節解釋。第一章討論針對每個線程創建的組件&#xff0c;第二章…

【機器視覺】——光源篇(分類、選型)

目錄 ? 一、光源相關知識 1、光的作用 2、光的顏色 二、光源的種類

ABB機器人 系統參數配置

系統參數用于定義系統配置并在出廠時根據客戶的需要定義。 可使用 FlexPendant 或 RobotStudio Online 編輯系統參數。 此步驟介紹如何查看 系統參數配置。 操作 &#xff1a; 1. 在 ABB 菜單上&#xff0c;點擊控制面板。 2. 點擊配置。顯示選定主題的可用類型列表。 3. 點…

MFC BCGControlBar 庫 使用方法

安裝 BCGControlBar 庫到你的計算機&#xff1a; 解壓縮 BCGControlBar.zip &#xff08;比如&#xff0c;到 c:\bcg 目錄中&#xff09;把 c:\bcg\bin 增加到你的 path 環境變量中&#xff0c;運行 Visual C 并且打開 Tools | Options 對話框&#xff0c;切換到Directories 頁…

四則運算2開發簡介

四則運算2在四則運算1的基礎之上&#xff0c;又添加了新的功能&#xff0c;但是我覺得四則運算2的難度比四則運算1增大了很多&#xff0c;我在編程的過程中&#xff0c;遇到的最大難度就是不知該如何更好的融合各個功能之間的關系。 寫到現在&#xff0c;四則運算2主要實現了以…

ABB機器人的 備份與恢復

保存內容 備份功能可保存上下文中的所有系統參數、系統模塊和程序模塊。 備份內容 數據保存于用戶指定的目錄中。 默認路徑可加以設置。 目錄分為四個子目錄&#xff1a;Backinfo、Home、Rapid 和 Syspar。 System.xml 也保存于包含用戶設置的 ../backup &#xff08;根…

flask項目開發中,遇到http 413錯誤

在flask項目中&#xff0c;上傳文件時后臺報http 413 Request Entity Too Large 請求體太大錯誤&#xff01; 解決的2種方法&#xff1a; 1.在flask配置中設置 MAX_CONTENT_LENGTH的值; 如設置為20M ( MAX_CONTENT_LENGTH20*1024*1024) 這時小于20M的文件都可以上傳 相關連接&…

【機器視覺】——畸變與矯正

目錄 一、什么是畸變?畸變的原因是什么? 1、徑向畸變(桶形畸變和枕形畸變)

ApplicationContextAware 接口

一、這個接口有什么用&#xff1f; 當一個類實現了這個接口&#xff08;ApplicationContextAware&#xff09;之后&#xff0c;這個類就可以方便獲得ApplicationContext中的所有bean。換句話說&#xff0c;就是這個類可以直接獲取spring配置文件中&#xff0c;所有有引用到的be…

Java之泛型練習

package cn.itcast.generics;import java.util.Comparator; import java.util.Iterator; import java.util.TreeSet;/** 方法一&#xff1a;實現Comparable接口*/ //class Person implements Comparable<Person> {//實現Comparable接口&#xff0c;使得集合元素具備可比較…

ABB 配置文件

配置文件 配置文件是列出系統參數值的文本文件。 注意&#xff1a; 如果該參數指定默認值&#xff0c;那么就不會被列在 配置文件。 控制器中有六個配置區域&#xff0c;配置文件保存為后綴 .CFG文件。 配置文件默認保存在系統文件夾SYSPAR&#xff0c;例如.. \ MySystem\ …

巨杉db

巨杉數據庫 and mongo db ,分布式數據庫&#xff0c; 轉載于:https://www.cnblogs.com/feiyun8616/p/8178116.html

【深度學習】——物體檢測細節處理(NMS、樣本不均衡、遮擋物體)

目錄 一、候選框大量重疊問題 1、NMS核心思想 2、 步驟&#xff1a; 3、缺陷 4、改進 1&#xff09;soft NMS——衰減的方式來減小預測框的分類得分 2&#xff09;softer nms——增加了位置置信度 二、樣本不平衡問題 1、不平滑的來源&#xff08;3方面&#xff09; 1&a…

忙著,快樂著

無比充實的周末&#xff0c;好久沒有這樣忙過了&#xff0c;周六早上七點多起床去上考研課&#xff0c;上了整整一天&#xff0c;晚上回到寢室用吃飯的時間讓自己放松一下&#xff0c;看了一會兒綜藝節目&#xff0c;吃晚飯就開始寫這次的代碼&#xff0c;寫累了就去洗洗睡了&a…

ABB Fronius TPS 4000/5000 IRC5 接口

在RobotStudio生成機器人系統時&#xff0c;選擇&#xff1a; Power Source option 650-9 Fronius TPS 4000/5000。Fronius的設備類別和設置被激活。此選項支持福尼斯TPS 4000/5000弧焊電機&#xff0c;包括支持三種焊接模式&#xff1a; 1 Job模式 2 修正的Job模式 …