poj1231 模拟?简单几何?

来源:互联网 发布:广西公务员网络考试 编辑:程序博客网 时间:2024/05/18 15:50
/** * poj1231 简单几何 * 这题也根本不是什么搜索题 * 先把所有字母的方块的四个边的值求出来 * 然后为了划分各个字母独立的区块,将原有的方块进行扩充 * 比如 *   B *       B D *         D * 就需要将原有的B方框向下扩充到D,将原有的D方框向上扩充到B * 合并的规则就是 *              if(left[i] <= right[j] && left[i] > left[j]) left[i] = left[j]; *              if(right[i] >= left[j] && right[i] < right[j]) right[i] = right[j]; *              if(top[i] <= bottom[j] && top[i] > top[j]) top[i] = top[j]; *              if(bottom[i] >= top[j] && bottom[i] < bottom[j]) bottom[i] = bottom[j];  * 由于扩充都是对称的,所以如果两个方块不能分割,就会相等,所以最后检查是否有相同的方块就行了 */#include <cstdio>using namespace std;const int MAX_NUM = 27;int left[MAX_NUM],right[MAX_NUM],top[MAX_NUM],bottom[MAX_NUM];int main(){    int t,k,p;    int x,y;    scanf("%d",&t);    while(t--){        scanf("%d%d",&k,&p);        for(int i=0;i<k;++i){            left[i] = 1<<30;            top[i] = 1<< 30;            right[i] = 0;            bottom[i] = 0;        }        for(int i=0;i<k;++i){            for(int j=0;j<p;++j){                scanf("%d%d",&x,&y);                left[i] = (x < left[i]) ? x : left[i];                right[i] = (x > right[i]) ? x : right[i];                top[i] = (y < top[i]) ? y : top[i];                bottom[i] = (y > bottom[i]) ? y : bottom[i];            }        }        for(int i=0;i<k;++i){            for(int j=0;j<k;++j){                if(j==i) continue;                if(left[i] <= right[j] && left[i] > left[j]) left[i] = left[j];                if(right[i] >= left[j] && right[i] < right[j]) right[i] = right[j];                if(top[i] <= bottom[j] && top[i] > top[j]) top[i] = top[j];                if(bottom[i] >= top[j] && bottom[i] < bottom[j]) bottom[i] = bottom[j];             }        }        bool flag=true;        for(int i=0;i<k;++i){            for(int j=0;j<k;++j){                if(j==i) continue;                if(left[i] == left[j] && right[i] == right[j] && top[i] == top[j] && bottom[i] == bottom[j]){                    flag = false;                }            }        }        if(flag){            printf("YES\n");        }        else{            printf("NO\n");        }    }    return 0;}

0 0
原创粉丝点击