热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

扫描线三巨头hdu1928hdu1255hdu1542[POJ1151]

学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很

学习链接:http://blog.csdn.net/lwt36/article/details/48908031

学习扫描线主要学习的是一种扫描的思想,后期可以求解很多问题。

 

扫描线求矩形周长并

hdu 1928

Picture

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


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 <&#61; 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

 

Source
IOI 1998

 

Recommend
linle

1 //#pragma comment(linker, "/STACK:1024000000,1024000000")
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define clr(x) memset(x,0,sizeof(x))
8 #define MAXN 50010
9 using namespace std;
10 struct edgx
11 {
12 int l,u,x;
13 int d;
14 }edgex[MAXN];
15 struct edgy
16 {
17 int l,r,y;
18 int d;
19 }edgey[MAXN];
20 struct seg
21 {
22 int l,r,cov,len;
23 }segt[MAXN<<2];
24 int cntx,cnty;
25 int x[MAXN],y[MAXN],vec[MAXN];
26 bool cmpy(edgy a,edgy b)
27 {
28 if(a.y&#61;&#61;b.y) return a.d>b.d;
29 return a.y<b.y;
30 }
31 bool cmpx(edgx a,edgx b)
32 {
33 if(a.x&#61;&#61;b.x) return a.d>b.d;
34 return a.x<b.x;
35 }
36 void init(int i,int l,int r)
37 {
38 segt[i]&#61;(seg){l,r,0,0};
39 if(l&#61;&#61;r)
40 return ;
41 int mid&#61;(l&#43;r)>>1;
42 init(i<<1,l,mid);
43 init(i<<1|1,mid&#43;1,r);
44 return ;
45 }
46 void pushup(int i)
47 {
48 if(segt[i].cov)
49 {
50 segt[i].len&#61;vec[segt[i].r&#43;1]-vec[segt[i].l];
51 }
52 else if(segt[i].l&#61;&#61;segt[i].r)
53 {
54 segt[i].len&#61;0;
55 }
56 else
57 {
58 segt[i].len&#61;segt[i<<1].len&#43;segt[i<<1|1].len;
59 }
60 return ;
61 }
62 void update(int i,int l,int r,int value)
63 {
64 if(segt[i].l>&#61;l && segt[i].r<&#61;r)
65 {
66 segt[i].cov&#43;&#61;value;
67 pushup(i);
68 return ;
69 }
70 int mid&#61;(segt[i].l&#43;segt[i].r)>>1;
71 if(mid>&#61;r)
72 {
73 update(i<<1,l,r,value);
74 }
75 else if(mid<l)
76 {
77 update(i<<1|1,l,r,value);
78 }
79 else
80 {
81 update(i<<1,l,r,value);
82 update(i<<1|1,l,r,value);
83 }
84 pushup(i);
85 return ;
86 }
87 int main()
88 {
89 int x1,x2,y1,y2,n,m,T,ans,l,r,k;
90 while(scanf("%d",&n)!&#61;EOF)
91 {
92 cntx&#61;0;
93 cnty&#61;0;
94 for(int i&#61;1;i<&#61;n;i&#43;&#43;)
95 {
96 scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
97 edgex[&#43;&#43;cntx]&#61;(edgx){y1,y2,x1,1};
98 x[cntx]&#61;x1;
99 edgex[&#43;&#43;cntx]&#61;(edgx){y1,y2,x2,-1};
100 x[cntx]&#61;x2;
101 edgey[&#43;&#43;cnty]&#61;(edgy){x1,x2,y1,1};
102 y[cnty]&#61;y1;
103 edgey[&#43;&#43;cnty]&#61;(edgy){x1,x2,y2,-1};
104 y[cnty]&#61;y2;
105 }
106 n<<&#61;1;
107 ans&#61;0;
108 memcpy(vec,x,sizeof(x));
109 sort(vec&#43;1,vec&#43;n&#43;1);
110 m&#61;unique(vec&#43;1,vec&#43;n&#43;1)-vec-1;
111 sort(edgey&#43;1,edgey&#43;n&#43;1,cmpy);
112 init(1,1,m);
113 for(int i&#61;1;i<&#61;n;i&#43;&#43;)
114 if(edgey[i].l<edgey[i].r)
115 {
116 k&#61;segt[1].len;
117 l&#61;lower_bound(vec&#43;1,vec&#43;m&#43;1,edgey[i].l)-vec;
118 r&#61;lower_bound(vec&#43;1,vec&#43;m&#43;1,edgey[i].r)-vec;
119 update(1,l,r-1,edgey[i].d);
120 ans&#43;&#61;abs(segt[1].len-k);
121 }
122 memcpy(vec,y,sizeof(y));
123 sort(vec&#43;1,vec&#43;n&#43;1);
124 m&#61;unique(vec&#43;1,vec&#43;n&#43;1)-vec-1;
125 sort(edgex&#43;1,edgex&#43;n&#43;1,cmpx);
126 init(1,1,m);
127 for(int i&#61;1;i<&#61;n;i&#43;&#43;)
128 if(edgex[i].l<edgex[i].u)
129 {
130 k&#61;segt[1].len;
131 l&#61;lower_bound(vec&#43;1,vec&#43;m&#43;1,edgex[i].l)-vec;
132 r&#61;lower_bound(vec&#43;1,vec&#43;m&#43;1,edgex[i].u)-vec;
133 update(1,l,r-1,edgex[i].d);
134 ans&#43;&#61;abs(segt[1].len-k);
135 }
136 printf("%d\n",ans);
137 }
138 return 0;
139 }

 

hdu 1255 矩阵面积交

覆盖的面积

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5718    Accepted Submission(s): 2854


Problem Description
给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.

 

Input
输入数据的第一行是一个正整数T(1<&#61;T<&#61;100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1<&#61;N<&#61;1000),代表矩形的数量,然后是N行数据,每一行包含四个浮点数,代表平面上的一个矩形的左上角坐标和右下角坐标,矩形的上下边和X轴平行,左右边和Y轴平行.坐标的范围从0到100000.

注意:本题的输入数据较多,推荐使用scanf读入数据.

 

Output
对于每组测试数据,请计算出被这些矩形覆盖过至少两次的区域的面积.结果保留两位小数.

 

Sample Input
2 5 1 1 4 2 1 3 3 7 2 1.5 5 4.5 3.5 1.25 7.5 4 6 3 10 7 3 0 0 1 1 1 0 2 1 2 0 3 1

 

Sample Output
7.63 0.00

 

Author
Ignatius.L & weigang Lee

1 //#pragma comment(linker, "/STACK:1024000000,1024000000")
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define clr(x) memset(x,0,sizeof(x))
8 #define MAXN 10010
9 using namespace std;
10 struct edg
11 {
12 double l,r,y;
13 int d;
14 }edge[MAXN];
15 struct seg
16 {
17 int l,r,cov;
18 double len1,len2;
19 }segt[MAXN<<2];
20 int cnt;
21 double x[MAXN];
22 bool cmp(edg a,edg b)
23 {
24 if(a.y&#61;&#61;b.y) return a.d>b.d;
25 return a.y<b.y;
26 }
27 double max(double a,double b)
28 {
29 return a>b?a:b;
30 }
31 void init(int i,int l,int r)
32 {
33 segt[i]&#61;(seg){l,r,0,0,0};
34 if(l&#61;&#61;r)
35 return ;
36 int mid&#61;(l&#43;r)>>1;
37 init(i<<1,l,mid);
38 init(i<<1|1,mid&#43;1,r);
39 return ;
40 }
41 void pushup(int i)
42 {
43 if(segt[i].cov>&#61;2)
44 {
45 segt[i].len2&#61;segt[i].len1&#61;x[segt[i].r&#43;1]-x[segt[i].l];
46 }
47 else if(segt[i].cov&#61;&#61;1)
48 {
49 segt[i].len1&#61;x[segt[i].r&#43;1]-x[segt[i].l];
50 if(segt[i].l&#61;&#61;segt[i].r)
51 segt[i].len2&#61;0;
52 else
53 segt[i].len2&#61;max(segt[i<<1].len1,segt[i<<1].len2)&#43;max(segt[i<<1|1].len1,segt[i<<1|1].len2);
54 }
55 else
56 {
57 if(segt[i].l&#61;&#61;segt[i].r)
58 {
59 segt[i].len1&#61;segt[i].len2&#61;0;
60 }
61 else
62 {
63 segt[i].len2&#61;segt[i<<1].len2&#43;segt[i<<1|1].len2;
64 segt[i].len1&#61;segt[i<<1].len1&#43;segt[i<<1|1].len1;
65 }
66 }
67 return ;
68 }
69 void update(int i,int l,int r,int value)
70 {
71 if(segt[i].l>&#61;l && segt[i].r<&#61;r)
72 {
73 segt[i].cov&#43;&#61;value;
74 pushup(i);
75 return ;
76 }
77 int mid&#61;(segt[i].l&#43;segt[i].r)>>1;
78 if(mid>&#61;r)
79 {
80 update(i<<1,l,r,value);
81 }
82 else if(mid<l)
83 {
84 update(i<<1|1,l,r,value);
85 }
86 else
87 {
88 update(i<<1,l,r,value);
89 update(i<<1|1,l,r,value);
90 }
91 pushup(i);
92 return ;
93 }
94 int main()
95 {
96 int T,n,m,k,u,v;
97 double x1,x2,y1,y2,ans,l,r;
98 scanf("%d",&T);
99 while(T--)
100 {
101 scanf("%d",&n);
102 cnt&#61;0;
103 ans&#61;0;
104 for(int i&#61;1;i<&#61;n;i&#43;&#43;)
105 {
106 scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
107 edge[&#43;&#43;cnt]&#61;(edg){x1,x2,y1,1};
108 x[cnt]&#61;x1;
109 edge[&#43;&#43;cnt]&#61;(edg){x1,x2,y2,-1};
110 x[cnt]&#61;x2;
111 }
112 n<<&#61;1;
113 sort(x&#43;1,x&#43;n&#43;1);
114 m&#61;unique(x&#43;1,x&#43;n&#43;1)-x-1;
115 sort(edge&#43;1,edge&#43;n&#43;1,cmp);
116 init(1,1,m);
117 for(int i&#61;1;i)
118 if(edge[i].r>edge[i].l)
119 {
120 l&#61;lower_bound(x&#43;1,x&#43;m&#43;1,edge[i].l)-x;
121 r&#61;lower_bound(x&#43;1,x&#43;m&#43;1,edge[i].r)-x;
122 update(1,l,r-1,edge[i].d);
123 ans&#43;&#61;segt[1].len2*(edge[i&#43;1].y-edge[i].y);
124 }
125 printf("%0.2lf\n",ans);
126 }
127 return 0;
128 }

 

 

hdu 1542 [POJ 1151] 区间面积并

Atlantis

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12537    Accepted Submission(s): 5257


Problem Description
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe different regions of Atlantis. Your friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to write a program that calculates this quantity.

 

Input
The input file consists of several test cases. Each test case starts with a line containing a single integer n (1<&#61;n<&#61;100) of available maps. The n following lines describe one map each. Each of these lines contains four numbers x1;y1;x2;y2 (0<&#61;x1
The input file is terminated by a line containing a single 0. Don’t process it.

 

Output
For each test case, your program should output one section. The first line of each section must be “Test case #k”, where k is the number of the test case (starting with 1). The second one must be “Total explored area: a”, where a is the total explored area (i.e. the area of the union of all rectangles in this test case), printed exact to two digits to the right of the decimal point.

Output a blank line after each test case.

 

Sample Input
2 10 10 20 20 15 15 25 25.5 0

 

Sample Output
Test case #1 Total explored area: 180.00

 

Source
Mid-Central European Regional Contest 2000

卡格式&#xff0c;不说了&#xff0c;都是泪。

1 //#pragma comment(linker, "/STACK:1024000000,1024000000")
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define clr(x) memset(x,0,sizeof(x))
8 #define MAXN 10010
9 using namespace std;
10 struct edg
11 {
12 double l,r,y;
13 int d;
14 }edge[MAXN];
15 struct seg
16 {
17 int l,r,cov;
18 double len;
19 }segt[MAXN<<2];
20 int cnt;
21 double x[MAXN];
22 bool cmp(edg a,edg b)
23 {
24 if(a.y&#61;&#61;b.y) return a.d>b.d;
25 return a.y<b.y;
26 }
27 double max(double a,double b)
28 {
29 return a>b?a:b;
30 }
31 void init(int i,int l,int r)
32 {
33 segt[i]&#61;(seg){l,r,0,0};
34 if(l&#61;&#61;r)
35 return ;
36 int mid&#61;(l&#43;r)>>1;
37 init(i<<1,l,mid);
38 init(i<<1|1,mid&#43;1,r);
39 return ;
40 }
41 void pushup(int i)
42 {
43 if(segt[i].cov)
44 {
45 segt[i].len&#61;x[segt[i].r&#43;1]-x[segt[i].l];
46 }
47 else if(segt[i].l&#61;&#61;segt[i].r)
48 {
49 segt[i].len&#61;0;
50 }
51 else
52 {
53 segt[i].len&#61;segt[i<<1].len&#43;segt[i<<1|1].len;
54 }
55 return ;
56 }
57 void update(int i,int l,int r,int value)
58 {
59 if(segt[i].l>&#61;l && segt[i].r<&#61;r)
60 {
61 segt[i].cov&#43;&#61;value;
62 pushup(i);
63 return ;
64 }
65 int mid&#61;(segt[i].l&#43;segt[i].r)>>1;
66 if(mid>&#61;r)
67 {
68 update(i<<1,l,r,value);
69 }
70 else if(mid<l)
71 {
72 update(i<<1|1,l,r,value);
73 }
74 else
75 {
76 update(i<<1,l,r,value);
77 update(i<<1|1,l,r,value);
78 }
79 pushup(i);
80 return ;
81 }
82 int main()
83 {
84 int T,n,m,k,u,v;
85 double x1,x2,y1,y2,ans,l,r;
86 int kase&#61;0;
87 while(scanf("%d",&n) && n!&#61;0)
88 {
89 printf("Test case #%d\n",&#43;&#43;kase);
90 cnt&#61;0;
91 ans&#61;0;
92 for(int i&#61;1;i<&#61;n;i&#43;&#43;)
93 {
94 scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
95 edge[&#43;&#43;cnt]&#61;(edg){x1,x2,y1,1};
96 x[cnt]&#61;x1;
97 edge[&#43;&#43;cnt]&#61;(edg){x1,x2,y2,-1};
98 x[cnt]&#61;x2;
99 }
100 n<<&#61;1;
101 sort(x&#43;1,x&#43;n&#43;1);
102 m&#61;unique(x&#43;1,x&#43;n&#43;1)-x-1;
103 sort(edge&#43;1,edge&#43;n&#43;1,cmp);
104 init(1,1,m);
105 for(int i&#61;1;i)
106 if(edge[i].r>edge[i].l)
107 {
108 l&#61;lower_bound(x&#43;1,x&#43;m&#43;1,edge[i].l)-x;
109 r&#61;lower_bound(x&#43;1,x&#43;m&#43;1,edge[i].r)-x;
110 update(1,l,r-1,edge[i].d);
111 ans&#43;&#61;segt[1].len*(edge[i&#43;1].y-edge[i].y);
112 }
113 printf("Total explored area: %0.2lf\n",ans);
114 printf("\n");
115 }
116 return 0;
117 }

 


转载于:https://www.cnblogs.com/wujiechao/p/6730638.html


推荐阅读
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文介绍了如何利用JavaScript或jQuery来判断网页中的文本框是否处于焦点状态,以及如何检测鼠标是否悬停在指定的HTML元素上。 ... [详细]
  • 本文介绍了如何使用JQuery实现省市二级联动和表单验证。首先,通过change事件监听用户选择的省份,并动态加载对应的城市列表。其次,详细讲解了使用Validation插件进行表单验证的方法,包括内置规则、自定义规则及实时验证功能。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 在前两篇文章中,我们探讨了 ControllerDescriptor 和 ActionDescriptor 这两个描述对象,分别对应控制器和操作方法。本文将基于 MVC3 源码进一步分析 ParameterDescriptor,即用于描述 Action 方法参数的对象,并详细介绍其工作原理。 ... [详细]
  • 本文介绍了在Windows环境下使用pydoc工具的方法,并详细解释了如何通过命令行和浏览器查看Python内置函数的文档。此外,还提供了关于raw_input和open函数的具体用法和功能说明。 ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • 本文探讨了Hive中内部表和外部表的区别及其在HDFS上的路径映射,详细解释了两者的创建、加载及删除操作,并提供了查看表详细信息的方法。通过对比这两种表类型,帮助读者理解如何更好地管理和保护数据。 ... [详细]
  • 导航栏样式练习:项目实例解析
    本文详细介绍了如何创建一个具有动态效果的导航栏,包括HTML、CSS和JavaScript代码的实现,并附有详细的说明和效果图。 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • PHP 编程疑难解析与知识点汇总
    本文详细解答了 PHP 编程中的常见问题,并提供了丰富的代码示例和解决方案,帮助开发者更好地理解和应用 PHP 知识。 ... [详细]
  • XNA 3.0 游戏编程:从 XML 文件加载数据
    本文介绍如何在 XNA 3.0 游戏项目中从 XML 文件加载数据。我们将探讨如何将 XML 数据序列化为二进制文件,并通过内容管道加载到游戏中。此外,还会涉及自定义类型读取器和写入器的实现。 ... [详细]
author-avatar
帅气小子勇哥
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有