zoukankan
html css js c++ java
NUAA上次热身赛的题目
自己用线段树写了一遍
还需...
#include
<
stdio.h
>
#include
<
math.h
>
#include
<
string
.h
>
struct
node
{
int
left, right;
node
*
pl,
*
pr;
int
height;
int
hCount;
int
Lheight, Rheight;
}
line[
80002
];
int
n;
int
lineCount;
int
point[
80002
];
int
area;
node
*
newNode()
{
node
*
pt
=
&
line[lineCount
++
];
memset(pt,
0
,
sizeof
(node));
return
pt;
}
node
*
makeTree(
int
ileft,
int
iright)
{
node
*
root
=
newNode();
root
->
left
=
ileft;
root
->
right
=
iright;
if
(iright
-
ileft
>
1
)
{
int
mid
=
(ileft
+
iright)
/
2
;
root
->
pl
=
makeTree(ileft,mid);
root
->
pr
=
makeTree(mid,iright);
}
return
root;
}
void
height(node
*
root,
int
height)
{
root
->
height
=
height;
root
->
Lheight
=
root
->
Rheight
=
height;
}
void
update(node
*
root,
int
x1,
int
x2,
int
h)
{
if
(root
->
left
==
x1
&&
root
->
right
==
x2)
{
height(root,h);
return
;
}
if
(root
->
hCount
==
1
)
{
height(root
->
pl,root
->
height);
height(root
->
pr,root
->
height);
}
root
->
hCount
++
;
if
(root
->
pl
->
right
>
x1)
{
if
(root
->
pl
->
right
>
x2)
update(root
->
pl,x1,x2,h);
else
{
int
mid
=
(root
->
left
+
root
->
right)
/
2
;
update(root
->
pl,x1,mid,h);
update(root
->
pr,mid,x2,h);
}
}
else
{
update(root
->
pr,x1,x2,h);
}
root
->
Lheight
=
root
->
pl
->
Lheight;
root
->
Rheight
=
root
->
pr
->
Rheight;
}
void
count(node
*
root,
int
x1,
int
x2)
{
if
(root
->
hCount
==
1
)
{
area
+=
(root
->
right
-
root
->
right)
*
root
->
height;
return
;
}
if
(root
->
right
-
root
->
left
<=
1
||
root
->
hCount
==
0
)
return
;
if
(root
->
pl
->
right
>
x1)
{
if
(root
->
pl
->
right
>=
x2)
{
count(root
->
pl,x1,x2);
}
else
{
int
mid
=
(root
->
left
+
root
->
right)
/
2
;
count(root
->
pl,x1,mid);
count(root
->
pr,mid,x2);
}
}
else
{
count(root
->
pr,x1,x2);
}
}
int
main()
{
lineCount
=
0
;
node
*
root
=
makeTree(
0
,
8002
);
while
(scanf(
"
%d
"
,
&
n)
!=
EOF
&&
n)
{
area
=
0
;
int
x1, x2, h;
int
i;
for
(i
=
0
;i
<
n;i
++
)
line[i].hCount
=
line[i].height
=
line[i].Lheight
=
line[i].Rheight
=
0
;
for
(i
=
0
;i
<
n;i
++
)
{
scanf(
"
%d%d%d
"
,
&
x1,
&
x2,
&
h);
update(root,x1,x2,h);
}
count(root,
0
,
8002
);
printf(
"
%d\n
"
,area);
}
return
0
;
}
查看全文
相关阅读:
2018 dnc .NET Core、.NET开发的大型网站列表、各大公司.NET职位精选,C#王者归来
下载docker镜像报错,dial tcp x.x.x.x:443: connect: connection refused
SpringMVC
MyBatis操作数据库——增删改查
MyBatis——Mapper配置并查询数据
MyBatis工程搭建
测试IOC&DI
SpringAOP测试
Spring连接Mysql
Spring 工程搭建
原文地址:https://www.cnblogs.com/SQL/p/920172.html
最新文章
Kubernetes Deployment 源码分析(二)
Kubernetes Deployment 源码分析(一)
Kubernetes client-go 源码分析
Kubernetes Job Controller 原理和源码分析(三)
Kubernetes client-go 源码分析
Kubernetes List-Watch 机制原理与实现
Kubernetes Job Controller 原理和源码分析(一)
博客开通啦
YII千万级PV架构经验分享--俯瞰篇--性能介绍
YII千万级PV架构经验分享--俯瞰篇--业务扩展演变
热门文章
YII千万级PV架构经验分享--俯瞰篇--YII扩展演变
YII千万级PV架构经验分享--俯瞰篇--架构即产品
YII千万级PV架构经验分享--理论篇
centOS 一键php环境安装-php博弈
团队自动化环境搭建与管理--php博弈
Arm Linux交叉编译Xalan-C++
问题的分类以及计算机如何解决这些问题
Asky极简教程:零基础1小时学编程,已更新前8节
首届.NET Core开源峰会
C#情怀与未来,怨天尤人还是抓住机会,能否跟上dnc新时代浪潮?
Copyright © 2011-2022 走看看