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

poj 1231 The Alphabet Game

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

poj 1231 The Alphabet Game

#include <stdio.h>#include <stdlib.h>#include <algorithm>#include <iostream>using namespace std;struct rect {    int left, right, top, bottom;    int rank_x;} rec[32];int T, K, P;int cmp_x(const void *a, const void *b){    return ((struct rect *)a)->left - ((struct rect *)b)->left;}int cmp_y(const void *a, const void *b){    return ((struct rect *)a)->top - ((struct rect *)b)->top;}inline int solve(){    int i, last, rank, mask;    qsort(rec, K, sizeof(rec[0]), cmp_x);    rank = 0;    for (i = 0; i < K; ) {        last = rec[i].right;        while (i < K && rec[i].left <= last) { rec[i].rank_x = rank; last = max(last, rec[i].right); i++;        }        rank++;    }    qsort(rec, K, sizeof(rec[0]), cmp_y);    for (i = 0; i < K; ) {        mask = 0;        last = rec[i].bottom;        while (i < K && rec[i].top <= last) { if (mask & (1 << rec[i].rank_x))     return 0; mask |= 1 << rec[i].rank_x; last = max(last, rec[i].bottom); i++;        }    }    return 1;}int main(){    int i, j, x, y;    scanf("%d", &T);    while (T--) {        scanf("%d%d", &K, &P);        for (i = 0; i < K; i++) { rec[i].left = rec[i].top = 1000000; rec[i].right = rec[i].bottom = 0; for (j = 0; j < P; j++) {     scanf("%d%d", &x, &y);     if (x < rec[i].left)         rec[i].left = x;     if (x > rec[i].right)         rec[i].right = x;     if (y < rec[i].top)         rec[i].top = y;     if (y > rec[i].bottom)         rec[i].bottom = y; }        }        printf("%sn", solve() ? "YES" : "NO");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375008.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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