HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
来源:互联网 发布:打车软件有几种 编辑:程序博客网 时间:2024/06/05 09:40
题意:一幅图上有N个点,M条边,边的权值表示通过这条边所需要的时间。有Q个任务,每次任务以Ci,Ti的形式给出Ci表示城市编号,Ti表示任务需要在Ti这个时间点完成.现在你拥有一个人,问至少还需要几个人才能完成所有城市给定时间上的任务。每个人都可以在任何时间点出现在任何城市
思路:和POJ3216一样的做法..
#include<cstdio>#include<cstring>#include<vector>using namespace std;const int maxn=1000+5;#define inf 1e9#define INF 1LL<<60struct Max_Match{ int n,m; vector<int> g[maxn]; bool vis[maxn]; int left[maxn]; void init(int n) { this->n=n;//this->m=m; for(int i=1; i<=n; ++i) g[i].clear(); memset(left,-1,sizeof(left)); } bool match(int u) { for(int i=0;i<g[u].size();++i) { int v=g[u][i]; if(!vis[v]) { vis[v]=true; if(left[v]==-1 || match(left[v])) { left[v]=u; return true; } } } return false; } int solve() { int ans=0; for(int i=1; i<=n; ++i) { memset(vis,0,sizeof(vis)); if(match(i)) ++ans; } return ans; }}MM;int cas=1,T;int n,m,Q;struct Node{int p,t;}node[maxn];long long d[maxn][maxn];void floyd(){for (int k = 0;k<n;k++)for (int i = 0;i<n;i++)for (int j = 0;j<n;j++)if (d[i][k]<INF && d[k][j]<INF)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);}bool check(int i,int j){return node[i].t+d[node[i].p][node[j].p]<=node[j].t;}int main(){scanf("%d",&T);while (T--){scanf("%d%d%d",&n,&m,&Q);for (int i = 0;i<=n;i++)for (int j = 0;j<=n;j++){ d[i][j] = i==j?0:INF;}while (m--){int u,v;long long di;scanf("%d%d%I64d",&u,&v,&di);d[u][v]=d[v][u]=di;}floyd();MM.init(Q);for (int i = 1;i<=Q;i++)scanf("%d%d",&node[i].p,&node[i].t);for (int i = 1;i<=Q;i++)for (int j = 1;j<=Q;j++)if (i!=j && check(i,j)){MM.g[i].push_back(j);}printf("Case %d: %d\n",cas++,Q-MM.solve()-1);} return 0;}
0 0
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- HDU--3991[Harry Potter and the Present II] Floyd预处理+最小路径覆盖
- hdu 3991 Harry Potter and the Present II //最小路径覆盖
- hdu 3991 Harry Potter and the Present II (最短路+最小路径覆盖)
- hdu 3991 Harry Potter and the Present II
- hdu 3991 Harry Potter and the Present II
- 最小匹配hdu 3991 Harry Potter and the Present
- hdu3991 Harry Potter and the Present II
- HDU 3987 Harry Potter and the Forbidden Forest 最小割
- 【HDU】3987 Harry Potter and the Forbidden Forest 最小割
- 【最小割】HDU 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest 最小割
- Harry Potter and the Hide Story HDU
- HDU--3987[Harry Potter and the Forbidden Forest] 求最小割集中的最小边数
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
- HDU 3987 Harry Potter and the Forbidden Forest (求割边最少的最小割)
- android studio 使用NDK
- KM(n^4)模板
- javascript继承
- C++重载
- 设置navigationbar透明
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- android面试题目2
- C语言进阶
- 图的遍历
- http://blog.csdn.net/innost?viewmode=contents
- ios打印NSInteger的时候去除警告
- 解决 RMContainerAllocator: Exception while unregistering java.lang.NullPointerException问题
- 第一行代码笔记之一Android系统架构
- hadoop案例实现之WordCount (计算单词出现的频数)