zoukankan      html  css  js  c++  java
  • Building Foundation

    #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
    ", ans);
    
        }
        return 0;
    }
  • 相关阅读:
    Spring boot 集成三种拦截方式
    Spring boot 异常处理配置
    Linux 启动、停止、重启tomcat工具(Shell脚本)
    Java 序列化对象工具类
    Spring boot 集成 Swagger
    Spring boot 项目导出可执行jar
    包扫描自定义注解类并实例化
    Zuul 网关搭建
    Hystrix + Hystrix Dashboard搭建(Spring Cloud 2.X)
    Feign + Hystrix 服务熔断和服务降级
  • 原文地址:https://www.cnblogs.com/NWUACM/p/6786140.html
Copyright © 2011-2022 走看看