NWU_ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<sstream>
#include<cstdlib>
#include<vector>
#include<string>
#include<cstdio>
#include<bitset>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define MP make_pair
using namespace std;

const int maxn = 666;
int n;
struct Seg
{
    int x1, y1, x2, y2;
    Seg(){}
    Seg(int a, int b, int c, int d) :x1(a), y1(b), x2(c), y2(d){}
}px[maxn], py[maxn];

bool cmpy(const Seg a, const Seg b)
{
    return a.y1 < b.y1;
}

bool judge(int i, int j, int& l, int& r)
{
    if(px[i].y1 == px[j].y1) return 0;
    if(px[i].x1 < px[j].x2 || px[j].x1 < px[i].x2) l = max(px[i].x1, px[j].x1), r = min(px[i].x2, px[j].x2);
    else return 0;
    return r > l;
}

bool ok(int y1, int y2, Seg a, int l, int r)
{
    if(a.x1 >= l && a.x1 <= r && a.y1 <= y1 && a.y2 >= y2) return 1;
    return 0;
}

int main()
{
    while(~scanf("%d", &n))
    {
        int cnt1 = 0, cnt2 = 0;
        int a, b, c, d;
        REP(i, n)
        {
            scanf("%d%d%d%d", &a, &b, &c, &d);
            if(a == c)
            {
                if(b > d) swap(d, b);
                py[cnt2++] = Seg(a, b, c, d);
            }
            else
            {
                if(a > c) swap(a, c);
                px[cnt1++] = Seg(a, b, c, d);
            }
        }
        sort(px, px+cnt1, cmpy);

        LL ans = 0;
        REP(i, cnt1) FF(j, i+1, cnt1)
        {
            int l, r;
            if(judge(i, j, l, r))
            {
                int tmp = 0;
                REP(k, cnt2)
                {
                    if(ok(px[i].y1, px[j].y1, py[k], l, r)) tmp++;
                }
                ans += ((LL)tmp*(tmp-1)) / 2;
            }
        }
        printf("%I64d\n", ans);

    }
    return 0;
}

 

posted on 2017-04-29 20:18  NWU_ACM  阅读(101)  评论(0编辑  收藏  举报