Gym
来源:互联网 发布:老婆胸大的体验知乎 编辑:程序博客网 时间:2024/05/20 18:44
题目链接:https://vjudge.net/problem/Gym-101490J
题意:有n个学生,每个学生有一个坐标代表位置,有n个老师,每个老师有一个坐标代表位置,他们之间需要互相配对,每对之间的价值为他们之间的曼哈顿距离,现在要你找一种配对方式使得他们之间的最大价值最小,输出这个最小值
解析:由于是配对,所以应该很容易想到二分图匹配,匈牙利原理是每次都找增广路,这个也是一样的,从第一个顶点增广路,记录增广路上的最大值,匹配完后和ans取一下最小即可
#include <bits/stdc++.h>using namespace std;const int maxn = 205;const int inf = 0x7fffffff;struct node{ int x,y;}a[maxn],b[maxn];int mapple[maxn][maxn];int vis[maxn],res,ans;vector<int>G[maxn*maxn];void dfs(int x,int cnt,int n){ if(cnt==n) { ans = min(ans,res); return ; } for(int i=0;i<(int)G[x].size();i++) { int y = G[x][i]; if(vis[y]) continue; vis[y] = 1; int tmp = res; res = max(res,mapple[x][y]); dfs(y,cnt+1,n); res = tmp; vis[y] = 0; }}int main(void){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d %d",&a[i].x,&a[i].y); for(int i=0;i<n;i++) scanf("%d %d",&b[i].x,&b[i].y); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { int tmp = abs(a[i].x-b[i].x)+abs(a[i].y-b[i].y); G[i].push_back(j+n); G[j+n].push_back(i); mapple[i][j+n] = tmp; mapple[j+n][i] = tmp; } } ans = inf; vis[0] = 1; dfs(0,0,n); printf("%d\n",ans); return 0;}
阅读全文
0 0
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Java——泛型
- 面试OR笔试38——游历城市
- ajaxfileUpload插件错误
- 练习4: 求一个n阶方阵对角线元素之和。
- 51nod 1580 铺管道(折线问题)
- Gym
- 进程间的通信方式
- 调试FFmpeg
- 引用类型总结——ECMAScript
- 九度[1103]-二次方程计算器
- LeetCode 121. Best Time to Buy and Sell Stock
- 练习5: 输入一个一维数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
- Python:AttributeError: ‘module’ object has no attribute ‘ArgumentParser’
- 两个有序链表序列的合并