HDU 4160 Dolls (最小路径覆盖=顶点数-最大匹配数)
Dolls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 869 Accepted Submission(s): 403
That is, the dolls cannot be rotated when fitting one inside another. Of course, each doll may contain at most one doll right inside it. Your goal is to fit dolls inside each other so that you minimize the number of outermost dolls.
5 4 8
27 10 10
100 32 523
3
1 2 1
2 1 1
1 1 2
4
1 1 1
2 3 2
3 2 2
4 4 4
0
1
3
2
题意:有n个布娃娃,可以用长宽高代表他们的特征,如果一个布娃娃的长宽高都比另一个小,那么这个布娃娃可以放到另一个的里面,问你求把布娃娃放置到另一个里,剩下的最少娃娃数量
思路: 最小路径覆盖=顶点数-最大匹配数
import java.io.*;
import java.util.*;
public class Main {
int n,MAX=10010;
int[][] map;
int[] link=new int[MAX];
boolean[] mark=new boolean[MAX];
public static void main(String[] args) {
new Main().work();
} void work(){
Scanner sc=new Scanner(new BufferedInputStream(System.in));
while(sc.hasNext()){
n=sc.nextInt();
if(n==0) break;
Node node[]=new Node[n];
for(int i=0;i<n;i++){
int wi=sc.nextInt();
int li=sc.nextInt();
int hi=sc.nextInt();
node[i]=new Node(wi,li,hi);
}
Arrays.sort(node);
map=new int[500][508];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(node[i].wi<node[j].wi&&node[i].li<node[j].li&&node[i].hi<node[j].hi){
map[i][j]=1;
}
}
}
hungary();
}
} void hungary(){
int ans=0;
Arrays.fill(link, 0);
for(int i=0;i<n;i++){
Arrays.fill(mark, false);
if(DFS(i))
ans++;
}
System.out.println(n-ans);
} boolean DFS(int x){
for(int i=0;i<n;i++){
if(map[x][i]==1&&!mark[i]){
mark[i]=true;
if(link[i]==0||DFS(link[i])){
link[i]=x;
return true;
}
}
}
return false;
} class Node implements Comparable<Node>{
int wi;
int li;
int hi;
Node(int wi,int li,int hi){
this.wi=wi;
this.li=li;
this.hi=hi;
}
public int compareTo(Node o) {
if(this.wi>o.wi) return 1;
if((this.wi==o.wi)&&(this.li>o.li)) return 1;
if((this.wi==o.wi)&&(this.li==o.li)&&(this.hi>o.hi))
return 1;
return -1;
}
}
}
HDU 4160 Dolls (最小路径覆盖=顶点数-最大匹配数)的更多相关文章
- HDU 3861 The King’s Problem 强连通分量 最小路径覆盖
先找出强连通分量缩点,然后就是最小路径覆盖. 构造一个二分图,把每个点\(i\)拆成两个点\(X_i,Y_i\). 对于原图中的边\(u \to v\),在二分图添加一条边\(X_u \to Y_v\ ...
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
- HDU 3861 The King’s Problem (强连通缩点+DAG最小路径覆盖)
<题目链接> 题目大意: 一个有向图,让你按规则划分区域,要求划分的区域数最少. 规则如下:1.所有点只能属于一块区域:2,如果两点相互可达,则这两点必然要属于同一区域:3,区域内任意两点 ...
- poj 3020 Antenna Placement(最小路径覆盖 + 构图)
http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ 3020 Antenna Placement(无向二分图的最小路径覆盖)
( ̄▽ ̄)" //无向二分图的最小路径覆盖数=顶点总数-最大匹配数/2(最大匹配数=最小点覆盖数) //这里最大匹配数需要除以2,因为每两个相邻的*连一条边,即<u,v>和< ...
- ●hihocoder #1394 网络流四·最小路径覆盖
题链: http://hihocoder.com/problemset/problem/1394 题解: 有向图最小路径覆盖:最少的路径条数不重不漏的覆盖所有点. 注意到在任意一个最小路径覆盖的方案下 ...
- HDU 3861 The King’s Problem 最小路径覆盖(强连通分量缩点+二分图最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 最小路径覆盖的一篇博客:https://blog.csdn.net/qq_39627843/ar ...
- (匹配 最小路径覆盖)Air Raid --hdu --1151
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 3861 The King's Problem(强连通分量缩点+最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=3861 题意: 国王要对n个城市进行规划,将这些城市分成若干个城市,强连通的城市必须处于一个州,另外一个州内的任意 ...
随机推荐
- C# Socket select模型
http://www.cnblogs.com/Clingingboy/archive/2011/07/04/2097806.html http://www.cnblogs.com/RascallySn ...
- 分布式session
前端用户请求经过随机分发之后,可能会命中后端任意的Web Server,并且 Web Server 也可能会因为各种不确定的原因宕机.在这种情况下,session 是很难在集群间同步的,而通过将ses ...
- git配合tortoiseGit的基础使用
转载自:http://www.cnblogs.com/ssor/archive/2012/02/04/2337823.html 一定要自己写出来才能牢记,所以我来写一下 git确实比svn好用的多了, ...
- Mysql 外键设置
MySql外键设置详解 (1) 外键的使用: 外键的作用,主要有两个: 一个是让数据库自己通过外键来保证数据的完整性和一致性 一个就是能够增加ER图的可读性 有些人认为外键的建立会给 ...
- ipa制作
打包ipa步骤: 项目名称 -> edit scheme -> 如图选择release 点击close后,选择真机 然后command+b编译程序,右击app,show in Finder ...
- 系统运维-hub, repeater, switch, router初览
repeater, hub, switch, router都是针对与osi的7层网络模型的不同层而产生的设备,逐一概览如下: repeater:中继器 是网络物理层的一种连接设备,工作在osi的物理层 ...
- 转:按需加载html 图片 css js
按需加载是前端性能优化中的一项重要措施,按需加载是如何定义的呢?顾名思义,指的是当用户触发了动作时才加载对应的功能.触发的动作,是要看具体的业务场景而言,包括但不限于以下几个情况:鼠标点击.输入文字. ...
- HTML::Entities 编码或解码 HTML 实体的字符串
<pre name="code" class="html"><pre name="code" class="py ...
- 第四种:GCD
GCD 1> 概述 Grand Central Dispatch (GCD)是Apple开发的一种多核编程技术.主要用于优化应用程序以支持多核处理器以及其他对称多处理系统. GCD提供函数实现多 ...
- iOS系统自带的 UIAlertView 自动旋转的实现
这里主要解析 UIAlertView 的几个关键功能的实现: 随着设备屏幕的旋转而旋转: Alert弹出框,使用UIWindow来实现,就是说,不用依赖于当前显示在最前面的UIView. 实现源码参考 ...