栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3636 Nested Dolls

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3636 Nested Dolls

#include <cstdio>#include <algorithm>using namespace std;#define MAX_DOLL_NUM 20004struct Doll{    int width, height;}doll[MAX_DOLL_NUM], chain[MAX_DOLL_NUM];int doll_num;int chain_cnt;bool operator < (const Doll &a, const Doll &b){    if (a.width == b.width)        return a.height > b.height;    return a.width < b.width;}void input(){    scanf("%d", &doll_num);    for (int i = 0; i < doll_num; i++)        scanf("%d%d", &doll[i].width, &doll[i].height);}bool fit(Doll a, Doll b){    return a.width > b.width && a.height > b.height;}void work(){    chain_cnt = 0;    for (int i = 0; i < doll_num; i++)    {        bool fitted = false;        for (int j = 0; j < chain_cnt; j++) if (fit(doll[i], chain[j])) {     fitted = true;     chain[j] = doll[i];     break; }        if (!fitted)        { chain[chain_cnt++] = doll[i];        }    }}int main(){    int t;    scanf("%d", &t);    while (t--)    {        input();        sort(doll, doll + doll_num);        work();        printf("%dn", chain_cnt);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379523.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号