zoukankan      html  css  js  c++  java
  • Counting Rectangles

    Counting Rectangles
    Time Limit: 1000MS Memory Limit: 10000K
    Total Submissions: 1043 Accepted: 546

    Description
    We are given a figure consisting of only horizontal and vertical line segments. Our goal is to count the number of all different rectangles formed by these segments. As an example, the number of rectangles in the Figures 1 and 2 are 5 and 0 respectively.

    There are many intersection points in the figure. An intersection point is a point shared by at least two segments. The input line segments are such that each intersection point comes from the intersection of exactly one horizontal segment and one vertical segment.

    Input
    The first line of the input contains a single number M, which is the number of test cases in the file (1 <= M <= 10), and the rest of the file consists of the data of the test cases. Each test case begins with a line containing s (1 <= s <= 100), the number of line segments in the figure. It follows by s lines, each containing x and y coordinates of two end points of a segment respectively. The coordinates are integers in the range of 0 to 1000.

    Output
    The output for each test case is the number of all different rectangles in the figure described by the test case. The output for each test case must be written on a separate line.

    Sample Input

    2
    6
    0 0 0 20
    0 10 25 10
    20 10 20 20
    0 0 10 0
    10 0 10 20
    0 20 20 20
    3
    5 0 5 20
    15 5 15 25
    0 10 25 10

    Sample Output

    5
    0
    给你水平还有竖直的线段判断可以组成多少的矩形
    暴力姿势

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #define LL long long
    using namespace std;
    
    const int MAX = 11000;
    
    struct node
    {
        int x1;
        int y1;
        int x2;
        int y2;
    }H[120],S[120];
    
    int top1,top2;
    
    bool Judge(int h,int s)
    {
        if(S[s].y1>=H[h].y1&&S[s].y1<=H[h].y2&&H[h].x2>=S[s].x1&&H[h].x2<=S[s].x2)
        {
            return true;
        }
        return false;
    }
    
    int main()
    {
        int T;
        int n;
        int x1,y1,x2,y2;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            top1=0;
            top2=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
                if(x1==x2)
                {
                    H[top1].x1=x1;H[top1].y1=min(y1,y2);
                    H[top1].x2=x2;H[top1].y2=max(y1,y2);
                    top1++;
                }
                else if(y1==y2)
                {
                    S[top2].x1=min(x1,x2);S[top2].y1=y1;
                    S[top2].x2=max(x1,x2);S[top2].y2=y2;
                    top2++;
                }
            }
            int sum=0;
            for(int i=0;i<top1;i++)
            {
                for(int j=0;j<top2;j++)
                {
                    if(Judge(i,j))
                    {
                        for(int k=i+1;k<top1;k++)
                        {
                            if(Judge(k,j))
                            {
                                for(int s=j+1;s<top2;s++)
                                {
                                    if(Judge(i,s)&&Judge(k,s))
                                    {
                                        sum++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            printf("%d
    ",sum);
        }
        return 0;
    }
    
  • 相关阅读:
    Crumpet – 使用很简单的响应式前端开发框架
    太赞了!超炫的页面切换动画效果【附源码下载】
    你见过动物是怎么笑的吗?赶紧来看看【组图】
    Treed – 基于拖放 操作的,强大的树形编辑器
    Perfect Scrollbar – 完美的 jQuery 滚动条插件
    Jeet – 先进,直观,灵活的 CSS 网格系统
    舌尖上的设计!10个美味的餐馆和食品网站
    推荐15款最好的 Twitter Bootstrap 开发工具
    Web 前端开发人员和设计师必读精华文章【系列二十五】
    Seen.js – 使用 SVG 或者 Canvas 渲染 3D 场景
  • 原文地址:https://www.cnblogs.com/juechen/p/5255997.html
Copyright © 2011-2022 走看看