2018 ACM-ICPC徐州站网络赛 G题
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yyy ) means the wave is a rectangle whose vertexes are ( 000 , 000 ), ( xxx , 000 ), ( 000 , yyy ), ( xxx , yyy ). Every time the wave will wash out the trace of former wave in its range and remain its own trace of ( xxx , 000 ) -> ( xxx , yyy ) and ( 000 , yyy ) -> ( xxx , yyy ). Now the toad on the coast wants to know the total length of trace on the coast after n waves. It's guaranteed that a wave will not cover the other completely.
Input
The first line is the number of waves n(n≤50000)n(n \le 50000)n(n≤50000).
The next nnn lines,each contains two numbers xxx yyy ,( 0<x0 < x0<x , y≤10000000y \le 10000000y≤10000000 ),the iii-th line means the iii-th second there comes a wave of ( xxx , yyy ), it's guaranteed that when 1≤i1 \le i1≤i , j≤nj \le nj≤n ,xi≤xjx_i \le x_jxi≤xj and yi≤yjy_i \le y_jyi≤yj don't set up at the same time.
Output
An Integer stands for the answer.
Hint:
As for the sample input, the answer is 3+3+1+1+1+1=103+3+1+1+1+1=103+3+1+1+1+1=10

样例输入
3
1 4
4 1
3 3
样例输出
10
题目来源
ACM-ICPC 2018 徐州赛区网络预赛
题意:
有n个矩形按顺序出现在坐标轴上,后出现的矩形会覆盖之前出现的矩形, 问最后没被覆盖的边的长度(不含在坐标轴上的边)。
分析::
首先看到这题最先想到的就应该是按矩形加入的顺序从后往前开始计算边长。又因为题目有要求:不存在一个矩形被另一个矩形完全包含,所以说每一个矩形都有突出来的部分可以被计算在答案内。我们从后往前枚举矩形,被枚举过的矩形的边长加入到set中,新加入的矩形的计算方法就是根据当前矩形的边长在set中找到小于当前边长的最长边长(二分),然后更新答案:ans+=(当前边 - set中找到的小于当前边的最大边)。
有一个注意点是二分的时候用的upper_bound()需要使用set内置的,而不是直接调用STL,直接调用STL的话时间大概是(1100ms左右 TLE),使用set内封装的upper_bound的话只要(90ms)。。。。(震惊)
AC code:
#include<bits/stdc++.h>
using namespace std;
set<int> x;
set<int> y;
set<int>::iterator tx,ty;
int X[],Y[]; int main()
{
int n;
scanf("%d",&n);
x.insert();
y.insert();
for(register int i=;i<n;++i)
{
scanf("%d%d",&X[i],&Y[i]);
}
long long ans=;
for(int i=n-;i>=;--i)
{
tx=x.upper_bound(X[i]);//使用set内封装的二分
tx--;
ty=y.upper_bound(Y[i]);//使用set内封装的二分
//*ty=(upper_bound(y.begin(),y.end(),Y[i]))超时!!!!
ty--;
ans+=(X[i]-*tx);
ans+=(Y[i]-*ty);
x.insert(X[i]);
y.insert(Y[i]);
}
printf("%lld\n",ans);
return ;
}
2018 ACM-ICPC徐州站网络赛 G题的更多相关文章
- 2019 ICPC南京站网络赛 H题 Holy Grail(BF算法最短路)
计蒜客题目链接:https://nanti.jisuanke.com/t/41305 给定的起点是S,终点是T,反向跑一下就可以了,注意判负环以及每次查询需要添加边 AC代码: #include< ...
- 2016 ACM-ICPC 青岛站网络赛G题 题解
[参考博客][https://blog.csdn.net/Tawn0000/article/details/82255682] 题意: 将n个数按照每k个一组来合并,合并需要花费的cost是两个数的长 ...
- 2013 acm 长沙网络赛 G题 素数+枚举 Goldbach
题目 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3856 先预处理求出两个素数的和与积,然后枚举n-prime和n/pr ...
- ICPC青岛站网络赛-C-高效模拟
嗯这道辣鸡题,当时我队友写了错误的代码,我稍微改动了,思路基本上是对了,但是就是超时,我第一直觉是我这个算法思路是没有任何问题的,但是就是TLE,我感觉这个算法已经优化的不能再优化了啊...后面就怀疑 ...
- 2014 ACM/ICPC 鞍山赛区网络赛(清华命题)
为迎接10月17号清华命题的鞍山现场赛 杭电上的题目 Biconnected(hdu4997) 状态压缩DP Rotate(hdu4998) 相对任一点的旋转 Overt(hdu4999 ...
- hdu 5874 Friends and Enemies icpc大连站网络赛 1007 数学
#include<stdio.h> #include<iostream> #include<algorithm> #include<math.h> #i ...
- hdu 5876 Sparse Graph icpc大连站网络赛 1009 补图最短路
BFS+链表 代码改自某博客 #include<stdio.h> #include<iostream> #include<algorithm> #include&l ...
- ACM-ICPC 2018 徐州赛区网络预赛 G题
题目链接: https://nanti.jisuanke.com/t/31459 具体思路: 先顺序输入,然后回溯,假设已经加入了n个点,那么在加入的同时,首先看一下原先x轴上已经有过的点,找到第一个 ...
- 2017 ACM/ICPC 南宁区 网络赛 Overlapping Rectangles
2017-09-24 20:11:21 writer:pprp 找到的大神的代码,直接过了 采用了扫描线+线段树的算法,先码了,作为模板也不错啊 题目链接:https://nanti.jisuanke ...
随机推荐
- cmd 运行bcp 提示:'bcp' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
这个问题的原因是:bcp.exe文件的路径不在环境变量中, 我的环境:Windows10 ,SQL server2016(D:) 1.首先查找你的SQL Server2016的安装位置 找到快捷方式, ...
- django中视图函数中装饰器
方法一 给指定方法加 from django.utils.decorators import method_decorator class xx(View): @method_decorator(装饰 ...
- golang中,slice的几个易混淆点
slice在golang中是最常用的类型,一般可以把它作为数组使用,但是比数组要高效呀.不过,我感觉这个东西用的不好坑太多了.还是需要了解下他底层的实现 slice的结构定义 type slice s ...
- maven 学习---Maven 构建配置文件
什么是构建配置文件? 构建配置文件是一组配置的集合,用来设置或者覆盖 Maven 构建的默认配置.使用构建配置文件,可以为不同的环境定制构建过程,例如 Producation 和 Developmen ...
- HLAPI
和SPS硬件交互的API
- TP5 Request 请求对象【转】
app\index\controller\Index.php <?php namespace app\index\controller; use think\Request; class Ind ...
- 关与 @EnableConfigurationProperties 注解
@EnableConfigurationProperties注解的作用是: 让使用 @ConfigurationProperties 注解的类生效. 当@EnableConfigurationProp ...
- (七)OpenStack---M版---双节点搭建---Dashboard安装和配置
↓↓↓↓↓↓↓↓视频已上线B站↓↓↓↓↓↓↓↓ >>>>>>传送门 1.安装并配置 2.重启apache和memcached服务 3.验证 4.在Web界面创建网络 ...
- reduce计算数组中每个元素出现的次数 数组去重的几种方式 将多维数组转化为一维
// js计算数组中每个元素出现的次数 // var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice']; // var countedNames = ...
- 解决txt乱码:将windows新建txt转换成utf-8格式
场景:产品将版本发布说明发给配置管理员(我自己),我使用jenkins建的任务自动传这个版本发布说明文件(release_note.txt)到ftp以后,打开文件后发现乱码. 调试: 但是将文件另存为 ...