SGU 532 Building Foundation(组合计数)

题意:

给你一些线段,问你能够组成多少个矩形。
一开始想到四方的枚举,果断T,然后被提醒发现只需要先枚举两条竖线,然后
在寻找所有与这两个竖线相交的横线,ans+=n*(n-1)/2。

代码:

//
//  Created by  CQU_CST_WuErli
//  Copyright (c) 2015 CQU_CST_WuErli. All rights reserved.
//
// #include<bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#define CLR(x) memset(x,0,sizeof(x))
#define OFF(x) memset(x,-1,sizeof(x))
#define MEM(x,a) memset((x),(a),sizeof(x))
#define For_UVa if (kase!=1) cout << endl
#define BUG cout << "I am here" << endl
#define lookln(x) cout << #x << "=" << x << endl
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define rep(flag,start,end) for(int flag=start;flag<=end;flag++)
#define Rep(flag,start,end) for(int flag=start;flag>=end;flag--)
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
#define Root 1,n,1
#define BigInteger bign
template <typename T> T gcd(const T& a,const T& b) {return b==0?a:gcd(b,a%b);}
const int MAX_L=2005;// For BigInteger
const int INF_INT=0x3f3f3f3f;
const long long INF_LL=0x7fffffff;
const int MOD=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
typedef long long  ll;
using namespace std;

struct Line {
    int x1,x2,y1,y2;
    void read() {
        SII(x1,y1);
        SII(x2,y2);
        if (x1>x2) swap(x1,x2);
        if (y1>y2) swap(y1,y2);
    }
    bool operator < (const Line& rhs) const {
        return x1<rhs.x1;
    }
};

int n;
vector<Line> vl,hl;

bool judge(Line& v1,Line& v2,Line& h) {
    int l=v1.x1,r=v2.x1;
    int up=min(v1.y2,v2.y2),down=max(v1.y1,v2.y1);
    if (h.x1<=l && h.x2>=r && h.y1>=down && h.y1<=up) return true;
    return false;
}

int main(){
#ifdef LOCAL
    freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin);
//  freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);
#endif
    while (SI(n)==1) {
        Line tmp;
        vl.clear();hl.clear();
        for (int i=1;i<=n;i++) {
            tmp.read();
            if (tmp.x1==tmp.x2) vl.push_back(tmp);
            else hl.push_back(tmp);
        }
        sort(vl.begin(),vl.end());
        int ans=0;
        for (int i=0;i<vl.size();i++) {
            for (int j=i+1;j<vl.size();j++) {
                int cnt=0;
                for (int k=0;k<hl.size();k++) {
                    if (judge(vl[i],vl[j],hl[k])) cnt++;
                }       
                ans+=(cnt*(cnt-1))/2;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值