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
;
}
查看全文
相关阅读:
Hibernate(2)——Hibernate的实现原理总结和对其模仿的demo
Hibernate(1)——数据访问层的架构模式
JVM学习(4)——全面总结Java的GC算法和回收机制
JVM学习(3)——总结Java内存模型
JVM学习(2)——技术文章里常说的堆,栈,堆栈到底是什么,从os的角度总结
JVM学习(1)——通过实例总结Java虚拟机的运行机制
减小内存的占用问题——享元模式和单例模式的对比分析
继承、组合和接口用法——策略模式复习总结
软件工程的引入:Scrum开发框架总结
软件工程里的UML序列图的概念和总结
原文地址:https://www.cnblogs.com/SQL/p/920172.html
最新文章
python json.dumps中文乱码
使用ControlPersist特性自动登陆SSH服务器
Python 3 源码安装过程中无法导入ssl问题解决
4-Nginx配置小结如request_filename
3-nginx 之 proxy_pass详解
2.zookeeper数据弱一致性
22-docker系列文章
macos中docker的存储路径问题
23-docker容器之间共享目录
22-Dockerfile指令
热门文章
Hadoop学习笔记(1):概念和整体架构
千回百折:百度Java研发offer斩获记和经验分享
大量逻辑判断优化的思路——责任链模式复习总结及其和状态模式对比
策略模式的孪生兄弟——对状态模式的深度复习总结
百度互联网数据研发部电面:一面记录
Hibernate(6)—— 一对多 和 多对多关联关系映射(xml和注解)总结
2016网易春招Java在线笔试回忆录
Hibernate(5)—— 联合主键 、一对一关联关系映射(xml和注解) 和 领域驱动设计
Hibernate(4)——主键生成策略、CRUD 基础API区别的总结 和 注解的使用
Hibernate(3)——实例总结Hibernate对象的状态和ThreadLoacl封闭的session
Copyright © 2011-2022 走看看