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

poj 2843 Cutting Cake

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

poj 2843 Cutting Cake

#include<stdio.h>#define ll long long#define MAX_N 1024using namespace std;struct queue_node {    int y, x;};int set[MAX_N][MAX_N], cut[MAX_N][MAX_N];int N, M;int left, top, right, bottom;struct queue_node queue[MAX_N * MAX_N];int head, tail;int find(int *arr, int idx){    static int stk[MAX_N * MAX_N], sp;    for (sp = 0; arr[idx]; idx = arr[idx])        stk[sp++] = idx;    for (sp--; sp >= 0; sp--)        arr[stk[sp]] = idx;    return idx;}void push(int y, int x){    if (x < left || x > right || y < top || y > bottom)        return ;    if (cut[y][x])        return ;    cut[y][x] = 1;    if (cut[y][x - 1] && cut[y][x + 1]) {        set[y][x] = x + 1;        set[y][x - 1] = x + 1;    } else if (cut[y][x - 1])        set[y][x - 1] = x;    else if (cut[y][x + 1])        set[y][x] = x + 1;    queue[tail].y = y;    queue[tail].x = x;    tail++;}int bfs(int y, int x){    x = find(set[y], x);    if (cut[y][x])        x++;    if (x > right)        return 0;    head = tail = 0;    push(y, x);    while (head != tail) {        y = queue[head].y;        x = queue[head].x;        head++;        push(y - 1, x);        push(y + 1, x);        push(y, x - 1);        push(y, x + 1);    }    return 1;}int main(){    int i, j, ans;    scanf("%d%d", &N, &M);    while (M--) {        scanf("%d%d%d%d", &left, &top, &right, &bottom);        ans = 0;        for (i = top; i <= bottom; i++) while (bfs(i, left))     ans++;        printf("%dn", ans);    }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380634.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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