码迷,mamicode.com
首页 > 其他好文 > 详细

hdu5258简单枚举

时间:2015-06-06 21:56:44      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

百度之星复赛第一题。不明白这么水的题为何一堆人没过。。。这些人是咋晋级复赛的呢。。。

/*
 * Author    : ben
 */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef struct Bang {
    int x1, x2;
    int y1, y2;
    Bang(int xx1 = 0, int yy1 = 0, int xx2 = 0, int yy2 = 0) {
        x1 = xx1;
        x2 = xx2;
        y1 = yy1;
        y2 = yy2;
    }
} Bang;
Bang heng[30], shu[30];
int N, M, ans;
bool isCross(const Bang &b1, const Bang &b2) {
    if (b2.x1 >= b1.x1 && b2.x1 <= b1.x2) {
        if (b1.y1 >= b2.y1 && b1.y1 <= b2.y2) {
            return true;
        }
    }
    return false;
}
void work() {
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            for (int a = 0; a < M; a++) {
                if (!isCross(heng[i], shu[a]) || !isCross(heng[j], shu[a])) {
                    continue;
                }
                for (int b = a + 1; b < M; b++) {
                    if (isCross(heng[i], shu[b]) && isCross(heng[j], shu[b])) {
                        ans++;
                    }
                }
            }
        }
    }
}

int main() {
    int T, n;
    int x1, x2, y1, y2;
    scanf("%d", &T);
    for (int t = 1; t <= T; t++) {
        N = 0;
        M = 0;
        ans = 0;
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
            if (x1 == x2) {
                shu[M++] = Bang(x1, min(y1, y2), x2, max(y1, y2));
            } else {
                heng[N++] = Bang(min(x1, x2), y1, max(x1, x2), y2);
            }
        }
        work();
        printf("Case #%d:\n%d\n", t, ans);
    }
    return 0;
}

 

hdu5258简单枚举

标签:

原文地址:http://www.cnblogs.com/moonbay/p/4557287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!