hdu 3991 Harry Potter and the Present II (最短路+最小路径覆盖)
来源:互联网 发布:java 什么语言开发的 编辑:程序博客网 时间:2024/05/16 08:34
最小路径覆盖,用floyd求最短路,注意匹配时定点不是n个而是Q个,每个城市可能有多个人需要礼物
把每个点根据时间排下序免得超时
#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 1010#define inf 0x3fffffffint map[N][N],link[N],match[N],n;bool mp[N][N];struct op{int x,t;}p[1010];int cmp(const void *a,const void *b){struct op *c,*d;c=(struct op *)a;d=(struct op *)b;if(c->t!=d->t)return c->t-d->t;return c->x-d->x;}int find(int u){int i;for(i=0;i<n;i++){if(!link[i]&&mp[u][i]){link[i]=1;if(match[i]==-1||find(match[i])){match[i]=u;return 1;}}}return 0;}void floyd(){int i,j,k;for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(map[i][j]>map[i][k]+map[k][j])map[i][j]=map[i][k]+map[k][j];}int main(){int i,j,T,sum,m,Q,x,y,c,op=1;scanf("%d",&T);while(T--){scanf("%d%d%d",&n,&m,&Q);for(i=0;i<n;i++){for(j=0;j<n;j++)map[i][j]=inf;map[i][i]=0;}memset(mp,false,sizeof(mp));for(i=0;i<m;i++){scanf("%d%d%d",&x,&y,&c);if(map[x][y]>c)map[x][y]=map[y][x]=c;}floyd();for(i=0;i<Q;i++)scanf("%d%d",&p[i].x,&p[i].t); qsort(p,Q,sizeof(p[0]),cmp);for(i=0;i<Q;i++)for(j=i+1;j<Q;j++){if(p[j].t-p[i].t>=map[p[i].x][p[j].x])mp[i][j]=true;}sum=0;n=Q;memset(match,-1,sizeof(match));for(i=0;i<Q;i++){memset(link,0,sizeof(link));sum+=find(i);}printf("Case %d: ",op++);printf("%d\n",n-sum-1);}return 0;}
- hdu 3991 Harry Potter and the Present II (最短路+最小路径覆盖)
- 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(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
- hdu 3991 Harry Potter and the Present II
- 最小匹配hdu 3991 Harry Potter and the Present
- hdu3991 Harry Potter and the Present II
- 【HDU】3986 Harry Potter and the Final Battle 最短路
- HDU 3986 Harry Potter and the Final Battle 最短路
- HDU3986 Harry Potter and the Final Battle最短路
- HDU 3986 Harry Potter and the Final Battle 删除一条边的最长最短路
- hdu 3986 Harry Potter and the Final Battle(最短路+枚举删边)
- HDU 3986 Harry Potter and the Final Battle 删掉任意一条边的最长最短路
- HDU - 3986 Harry Potter and the Final Battle(最短路SPFA+枚举删边)
- hdu 3986 Harry Potter and the Final Battle 最短路spfa+枚举
- Qwt源码解读之QwtColorMap颜色类
- 并查集
- Ajax 简介主流
- 值栈 OGNL
- UVa 674 - Coin Change 背包dp
- hdu 3991 Harry Potter and the Present II (最短路+最小路径覆盖)
- hadoop 常用命令
- lowmem_reserve的理解
- 建立Threading.Task 多任务时,使用匿名Action导致的问题
- Android 用户界面---操作栏 Action Bar
- Win7 IIS7.5上部署Asp程序的两个问题
- hadoop wordcount
- linux网卡驱动程序设计
- Java集群之session共享解决方案