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
;
}
查看全文
相关阅读:
axios 和 fetch 区别对比
sql where条件后面跟select语句的三种实现方式
东北师范大学2021年数学分析考研试卷
东北师范大学2021年高等代数与解析几何考研试卷
东北大学2021年数学分析考研试卷
电子科技大学2021年数学分析考研试卷
电子科技大学2021年高等代数考研试卷
大连理工大学2021年数学分析考研试卷
大连理工大学2021年高等代数考研试卷
大连海事大学2021年数学分析考研试卷
原文地址:https://www.cnblogs.com/SQL/p/920172.html
最新文章
springboot+kafka中@KafkaListener如何动态指定多个topic(转载)
CentOS7.2安装Postgresql10.6(转载)
How To Backup and Restore PostgreSQL Database using pg_dump and psql
PostgreSQL使用pg_dump导出单个数据表的insert语句(转载)
浅析SpringSecurity对跨域非简单请求的Prefight预检请求的处理:requestMatchers(CorsUtils::isPreFlightRequest).permitAll()、及简单请求与非简单请求的理解
浅析SpringSecurity的AuthenticationEntryPoint认证入口点及其实现类简介及AccessDeineHandler
浅析Java注解的意义、分类、用途、如何自定义注解使用示例及Java注解的实现原理的分析
浅析Spring的@Bean注解:注解分类、简介,作用、好处及代码使用示例、Bean的xml方式和注解方式使用对比、@Bean的源码分析
go 语言file Seek( )函数用法
【转】linux 同步IO: sync、fsync与fdatasync
热门文章
why is this a deadlock in golang / waitgroup?
【转】什么是WaitGroup?其方法有什么作用?go语言学习
sort.Sort() interface in GoLang
golang 内存对齐
【转】go uintptr unsafe Pointer offset() 的使用
对象数组去重
手写 防抖函数 debounce
setupWebViewJavascriptBridge
软件版本比较
mysql 替换字符串
Copyright © 2011-2022 走看看