zoukankan      html  css  js  c++  java
  • hdu 5258 数长方形 离散化

    数长方形

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=5258

    Description

    小度熊喜欢玩木棒。一天他在玩木棒的时候,发现一些木棒会形成长方形。小度熊可能是处女座吧,他只会将木棒横竖摆放,这样会形成很多长方形。现在给你一些横竖摆放的木棒,请你帮小度熊数一数形成了多少个长方形。

    为了简化题目,一个木棒的端点不会在另一个木棒上,也就是说,木棒的端点不会在长方形上

    Input

    第一行一个整数T,表示T组数据,不超过100组。

    每组数据中,第一行是n,代表有多少个木棒,n不会超过25。接下来n行,每行4个整数x1,y1,x2,y2,代表木棒的坐标,绝对值不超过1000。

    所有的木棒都是横竖摆放的,也就是说x1=x2或者y1=y2,没有长为0的木棒。

    Output

    对于每组测试数据,先输出一行

    Case #i:

    然后输出一个整数,代表有多少个长方形。

    Sample Input

    2
    4
    3 0 3 3
    4 0 4 3
    2 1 5 1
    2 2 5 2
    4
    3 0 3 3
    4 0 4 3
    2 1 5 1
    2 2 -5 2

    Sample Output

    Case #1:
    1
    Case #2:
    0

    HINT

    题意

    题解:

    看到只有25个棍子,然后我就直接离散化一发,然后离散之后,就感觉就是傻逼题了……

    想怎么搞怎么搞

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 2000001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    int g[50][50];
    map<int,int> H1;
    map<int,int> H2;
    vector<int> x;
    vector<int> y;
    vector<int> kiss[50];
    struct node
    {
        int x1,x2,y1,y2;
    }a[100];
    int main()
    {
        //test;
        int t=read();
        for(int cas=1;cas<=t;cas++)
        {
            memset(g,0,sizeof(g));
            memset(a,0,sizeof(a));
            H1.clear();
            H2.clear();
            x.clear();
            y.clear();
            for(int i=0;i<50;i++)
                kiss[i].clear();
            int n=read();
            for(int i=0;i<n;i++)
            {
                a[i].x1=read(),a[i].y1=read(),a[i].x2=read(),a[i].y2=read();
                if(a[i].x1>a[i].x2)
                    swap(a[i].x1,a[i].x2);
                if(a[i].y1>a[i].y2)
                    swap(a[i].y1,a[i].y2);
                x.push_back(a[i].x1);
                x.push_back(a[i].x2);
                y.push_back(a[i].y1);
                y.push_back(a[i].y2);
            }
            sort(x.begin(),x.end());
            sort(y.begin(),y.end());
            x.erase(unique(x.begin(),x.end()),x.end());
            y.erase(unique(y.begin(),y.end()),y.end());
            for(int i=0;i<x.size();i++)
                H1[x[i]]=i;
            for(int i=0;i<y.size();i++)
                H2[y[i]]=i;
            for(int i=0;i<n;i++)
            {
                a[i].x1=H1[a[i].x1];
                a[i].x2=H1[a[i].x2];
                a[i].y1=H2[a[i].y1];
                a[i].y2=H2[a[i].y2];
                //cout<<a[i].x1<<" "<<a[i].y1<<" "<<a[i].x2<<" "<<a[i].y2<<endl;
            }
            for(int i=0;i<n;i++)
                if(a[i].x1==a[i].x2)
                    for(int j=a[i].y1;j<=a[i].y2;j++)
                        g[a[i].x1][j]=i+1;
            
            for(int i=0;i<n;i++)
                if(a[i].y1==a[i].y2)
                    for(int j=a[i].x1;j<=a[i].x2;j++)
                        if(g[j][a[i].y1]!=0)
                            kiss[g[j][a[i].y1]].push_back(i+1);
                            
            ll ans=0;
            for(int i=0;i<=n;i++)
            {
                for(int j=i+1;j<=n;j++)
                {
                    int flag=0;
                    for(int k=0;k<kiss[i].size();k++)
                    {
                        
                        for(int m=0;m<kiss[j].size();m++)
                        {
                            if(kiss[i][k]==kiss[j][m])
                            {
                                flag++;
                                break;
                            }
                            
                        }
                    }
                    ans+=flag*(flag-1)/2;
                }
            }
            printf("Case #%d:
    ",cas);
            cout<<ans<<endl;
        }
    }
  • 相关阅读:
    【小米OJ-找多少个等差数列】动态规划
    【小米OJ-找出可能的合的组合】深搜(dfs)
    【小米OJ-移除k位得到最小值】栈的应用
    【小米OJ-小米兔的轨迹】顺时针蛇形矩形
    Qt常用类
    file_operations
    Proc文件系统
    memset
    Source Insight快捷键大全
    内核内存分配
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4557260.html
Copyright © 2011-2022 走看看