zoukankan      html  css  js  c++  java
  • Hdu 4160 Dolls

    Problem Description
    Do you remember the box of Matryoshka dolls last week? Adam just got another box of dolls from Matryona. This time, the dolls have different shapes and sizes: some are skinny, some are fat, and some look as though they were attened. Specifically, doll i can be represented by three numbers wi, li, and hi, denoting its width, length, and height. Doll i can fit inside another doll j if and only if wi < wj , li < lj , and hi < hj .
    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.
     
    
    
    Input
    The input consists of multiple test cases. Each test case begins with a line with a single integer N, 1 ≤ N ≤ 500, denoting the number of Matryoshka dolls. Then follow N lines, each with three space-separated integers wi, li, and hi (1 ≤ wi; li; hi ≤ 10,000) denoting the size of the ith doll. Input is followed by a single line with N = 0, which should not be processed.
     
    
    
    Output
    For each test case, print out a single line with an integer denoting the minimum number of outermost dolls that can be obtained by optimally nesting the given dolls.
     
    //最少路径覆盖=节点数-最大匹配数
    //将每个点拆成2个点 i,i' 。若有边 i->j 则建立 i'->j 的边 所以肯定是二分图
    #include <iostream> #include <stdio.h> #include <string.h> #include <vector> using namespace std; int match[510]; int visit[510]; bool G[510][510]; int n; struct Record { int w; int l; int h; }r[510]; int cmp(int i,int j) { if(r[i].w>r[j].w&&r[i].l>r[j].l&&r[i].h>r[j].h) return 1; if(r[i].w<r[j].w&&r[i].l<r[j].l&&r[i].h<r[j].h) return -1; return 0; } bool dfs(int u) { int v; for(v=1;v<=n;v++) if(G[u][v]&&!visit[v]) { visit[v]=true; if(!match[v]||dfs(match[v])) { match[v]=u; return true; } } return false; } int main() { int i,j; while(scanf("%d",&n),n) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) G[i][j]=false; for(i=1;i<=n;i++) scanf("%d %d %d",&r[i].w,&r[i].l,&r[i].h); for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) { int flag=cmp(i,j); switch(flag) { case 1 :G[j][i]=true; break; case -1:G[i][j]=true; break; } } int ans=0; memset(match,0,sizeof(match)); for(i=1;i<=n;i++) { memset(visit,0,sizeof(visit)); if(dfs(i)) ans++; } printf("%d\n",n-ans); } return 0; }
  • 相关阅读:
    二货Mysql中设置字段的默认值问题
    Mongodb第一步资料
    时间时间
    嵌入式linux应用程序移植方法总结
    capwap DTSL 加密分析
    capwap协议重点分析
    一点论文写作心得
    live555+ffmpeg如何提取关键帧(I帧,P帧,B帧)
    “以图搜图”引擎及网站合集
    常见的希腊字母的读法
  • 原文地址:https://www.cnblogs.com/372465774y/p/3040283.html
Copyright © 2011-2022 走看看