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
;
}
查看全文
相关阅读:
文本图片分享
重构必备技能之条件表达式
重构必备技能之前言
NoSQL你知多少?
Jsoup获取全国地区数据(省市县镇村)(续) 纯干货分享
Jsoup获取全国地区数据(省市县镇村)
java字符串拼接技巧(StringBuilder使用技巧)
华为第七届无线编码大赛总结
linux设置java环境变量与开机自启
用Navicat连接Oracle数据库时报错ORA-28547:connection to server failed, probable Oracle Net admin error
原文地址:https://www.cnblogs.com/SQL/p/920172.html
最新文章
【高速接口-RapidIO】4、Xilinx RapidIO核详解
【高速接口-RapidIO】3、RapidIO串行物理层的包传输过程
【高速接口-RapidIO】2、RapidIO串行物理层的包与控制符号
【高速接口-RapidIO】1、RapidIO协议概述
【设计经验】3、ISE中烧录QSPI Flash以及配置mcs文件的加载速度与传输位宽
【设计经验】2、ISE中ChipScope使用教程
进程coredump的elf debug信息补全方法
openssl asynch_mode 使用libasan时的OOM问题
CentOS 7编译安装Tengine+PHP+MariaDB全程笔记
CentOS7 默认防火墙firewalld
热门文章
CentOS7 网络管理工具nmcli
github添加ssh公钥
python练习1(简单爬虫)
python学习笔记:第八天(模块)
python学习笔记:第七天(函数)
python学习笔记:第六天(流程控制语句)
python学习笔记:第五天( 字典)
python学习笔记:第五天( 列表、元组)
Bootstrap 入门到精通
利用Pluggable Protocol实现浏览器打开本地应用程序
Copyright © 2011-2022 走看看