zoukankan      html  css  js  c++  java
  • hdu 1828 Picture 切割线求周长

    Picture

    Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2144    Accepted Submission(s): 1139


    Problem Description
    A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wall. Their sides are all vertical or horizontal. Each rectangle can be partially or totally covered by the others. The length of the boundary of the union of all rectangles is called the perimeter.

    Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.



    The corresponding boundary is the whole set of line segments drawn in Figure 2.



    The vertices of all rectangles have integer coordinates.
     
    Input
    Your program is to read from standard input. The first line contains the number of rectangles pasted on the wall. In each of the subsequent lines, one can find the integer coordinates of the lower left vertex and the upper right vertex of each rectangle. The values of those coordinates are given as ordered pairs consisting of an x-coordinate followed by a y-coordinate.

    0 <= number of rectangles < 5000
    All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.

    Please process to the end of file.
     
    Output
    Your program is to write to standard output. The output must contain a single line with a non-negative integer which corresponds to the perimeter for the input rectangles.
     
    Sample Input
     
    7
    -15 0 5 10
    -5 8 20 25
    15 -4 24 14
    0 -6 16 4
    2 15 10 22
    30 10 36 20
    34 0 40 16
     
    Sample Output
    228
     
    /*
    统计周长
    */
    
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #define N 5003
    #define hxl 10003
    using namespace std;
    
    
    struct node
    {
        int begin;
        int end;
        int val;
        int flag;
    }Linex[N<<1],Liney[N<<1];
    int Hash[30000];
    
    
    bool cmp(node n1,node n2)
    {
        return n1.val<n2.val;
    }
    
    
    int make_x(int NN)
    {
        int sum=0,i,j;
        for(i=1;i<=NN;i++)
        {
            if(Linex[i].flag==1)
            {
                for(j=Linex[i].begin;j<Linex[i].end;j++)
                {
                    if(Hash[j]==0)
                    sum++;
                    Hash[j]++;
                }
            }
            else
            {
                for(j=Linex[i].begin;j<Linex[i].end;j++)
                {
                    if(Hash[j]==1)
                    sum++;
                    Hash[j]--;
                }
    
            }
        }
        return sum;
    }
    
    int make_y(int NN)
    {
        int sum=0,i,j;
        for(i=1;i<=NN;i++)
        {
            if(Liney[i].flag==1)
            {
                for(j=Liney[i].begin;j<Liney[i].end;j++)
                {
                    if(Hash[j]==0)
                    sum++;
                    Hash[j]++;
                }
            }
            else
            {
                for(j=Liney[i].begin;j<Liney[i].end;j++)
                {
                    if(Hash[j]==1)
                    sum++;
                    Hash[j]--;
                }
            }
        }
        return sum;
    }
    
    void make_ini(int NN)
    {
        int x1,y1,x2,y2,i,len=0,sum=0;
        for(i=1;i<=NN;i++)
        {
            scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
            x1+=hxl;y1+=hxl;y2+=hxl;x2+=hxl;
    
            Linex[++len].val=x1;
            Linex[len].begin=y1;
            Linex[len].end=y2;
            Linex[len].flag=1;
    
            Liney[len].val=y1;
            Liney[len].begin=x1;
            Liney[len].end=x2;
            Liney[len].flag=1;
    
            Linex[++len].val=x2;
            Linex[len].begin=y1;
            Linex[len].end=y2;
            Linex[len].flag=-1;
    
            Liney[len].val=y2;
            Liney[len].begin=x1;
            Liney[len].end=x2;
            Liney[len].flag=-1;
        }
        sort(Linex+1,Linex+1+len,cmp);
        sort(Liney+1,Liney+1+len,cmp);
        memset(Hash,0,sizeof(Hash));
        sum+=make_x(len);
        memset(Hash,0,sizeof(Hash));
        sum+=make_y(len);
        printf("%d
    ",sum);
    }
    
    int main()
    {
        int NN;
        while(scanf("%d",&NN)>0)
        {
            make_ini(NN);
        }
        return 0;
    }
  • 相关阅读:
    SQL Server2008中删除重复记录
    Php环境在Windows (server 2003) 服务器部署标准 白丁简明版
    国外服务器鸟文windows,时间12小时制,如何改成24小时呢?我来告诉你
    将Capicom调用代码封装到ActiveX——解决javascript调Capicom读取数字证书信息时,IE弹出安全提示的问题
    Linq处理List数据
    C#将窗口最小化到系统托盘,并显示图标和快捷菜单
    C# 将程序添加到启动项 (写入注册表),及从启动项中删除
    C#中string[]数组和list<string>泛型的相互转换
    IIS7.5部署ASP.NET失败
    IIS 7.5版本中一些诡异问题的解决方案
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3234338.html
Copyright © 2011-2022 走看看