zoukankan      html  css  js  c++  java
  • SGU 532. Building Foundation 暴力

    532. Building Foundation

    题目连接:

    http://acm.sgu.ru/problem.php?contest=0&problem=532

    Description

    A new office building is to appear in Berland soon. Its construction has just been started, and the first problem builders are facing is to lay the foundation.

    The ground at construction site area has already been hardened along n segments. Each segment is given by integer coordinates of its endpoints in the site area coordinate system. Every segment has a positive length and is parallel to either Ox axis or Oy axis. It's important to note that the ground hardening was done in such a way that only perpendicular segments could possibly have common points.

    The decision has been made for the foundation to have a rectangular form. The rectangle must have the following properties:

    it should have a positive area,

    its sides should be parallel to one of the coordinate axes,

    its sides should be situated on the hardened ground, i.e. each point of its perimeter should belong to at least one segment out of the n hardened ones.

    You are to help estimating the difficulty of choosing such a rectangle. Write a program that finds the number of rectangles that can possibly be used as a foundation.

    Input

    The first line contains integer n (1 ≤ n ≤ 600) — the number of hardened segments. Each of the following n lines contains four space-separated integers x1, y1, x2, y2 (-109 ≤ x1,y1,x2,y2 ≤ 109) — coordinates of the segments' endpoints. Each segment has positive length and is parallel to either Ox axis or Oy axis. No two horizontal segments have a common point. No two vertical segments have a common point.

    Output

    Print a single integer — the number of rectangles that can possibly be used as a foundation.

    Sample Input

    4

    0 0 1 0

    0 0 0 1

    1 1 1 -1

    1 1 0 1

    Sample Output

    1

    Hint

    题意

    在平面上给你n条平行于坐标轴的线段,然后问你能够组成多少个矩形

    题解:

    直接暴力枚举两条边,然后统计有多少条边同时经过这两条边就好了

    然后贡献就是n*(n-1)/2,n表示经过这两条边的边数

    代码

    #include<bits/stdc++.h>
    using namespace std;
    #define maxn 1005
    
    int x1[maxn],x2[maxn],yy1[maxn],y2[maxn];
    int cross(int k1,int k2)
    {
        if(x1[k1]==x2[k1]&&x1[k2]==x2[k2])
            return 0;
        if(yy1[k1]==y2[k1]&&y2[k2]==yy1[k2])
            return 0;
    
        if(yy1[k1]==y2[k1])
            swap(k1,k2);
    
        if(x1[k1]<=x2[k2]&&x1[k1]>=x1[k2] && yy1[k1]<=yy1[k2]&&y2[k1]>=yy1[k2])
            return 1;
        return 0;
    }
    bitset<maxn> s[maxn];
    int main()
    {
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d%d",&x1[i],&yy1[i],&x2[i],&y2[i]);
            if(x1[i]>x2[i])swap(x1[i],x2[i]);
            if(yy1[i]>y2[i])swap(yy1[i],y2[i]);
        }
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
                if(cross(i,j))
                    s[i][j]=1,s[j][i]=1;
        long long ans = 0;
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
            {
                bitset<maxn> t = s[i]&s[j];
                int p = t.count();
                ans+=p*(p-1)/2;
            }
        cout<<ans/2<<endl;
    }
  • 相关阅读:
    B2C电子商务网站的突围——再议什么是B2C网站,互联网营销 狼人:
    迅雷网站设计浅析,互联网营销 狼人:
    构建一个高性能的网页抓取器,互联网营销 狼人:
    Velocity China 2010大会回顾,互联网营销 狼人:
    尝试使用GraphicsMagick的缩略图功能,互联网营销 狼人:
    美妙的模电2013/4/18
    找素数 素数就是不能再进行等分的整数。比如:7,11。而9不是素数,因为它可以平分为3等份。
    WMI技术介绍和应用——查询硬件信息
    码农如何快速打造一个有设计感的网站 How to Make Your Site Look HalfDecent in Half an Hour
    poj321101背包
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5137621.html
Copyright © 2011-2022 走看看