Trace 2018徐州icpc网络赛 思维+二分
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) means the wave is a rectangle whose vertexes are ( 00 , 00 ), ( xx , 00 ), ( 00 , yy ), ( xx , yy ). Every time the wave will wash out the trace of former wave in its range and remain its own trace of ( xx , 00 ) -> ( xx , yy ) and ( 00 , yy ) -> ( xx , yy ). 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 \le 50000)n(n≤50000).
The next nn lines,each contains two numbers xxyy ,( 0 < x0<x , y \le 10000000y≤10000000 ),the ii-th line means the ii-th second there comes a wave of ( xx , yy ), it's guaranteed that when 1 \le i1≤i , j \le nj≤n,x_i \le x_jxi≤xj and y_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=10

样例输入复制
3
1 4
4 1
3 3
样例输出复制
10
题目来源
题意:有n次海浪,每次海浪会产生两段轨迹(0,y)到(x,y)和(x,0)到(x,y),后面的海浪会将前面的在(0,0)到(x,y)之间区域的海浪轨迹覆盖掉,问最后剩余的轨迹长度
分析:每段轨迹有效的贡献是在此轨迹被接下来所有轨迹覆盖一次后剩余的轨迹长度
所以我们考虑直接从后面往前面枚举
最后的轨迹长度肯定是可以直接加上的,没有其余的海浪能覆盖掉他,然后将其的轨迹点放进集合
接下来遍历到的点只要看集合里比他小的最大的数就是能覆盖掉他多少长度,减去这个长度就行
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 2e9+7;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll f( vector<ll> e ) {
ll sz = e.size(), ans = 0;
set<ll> s;
for( ll i = sz-1; i >= 0; i -- ) {
set<ll>::iterator it = s.lower_bound(e[i]);
if( it == s.begin() ) {
ans += e[i];
} else {
it --;
ans += e[i] - *it;
}
s.insert(e[i]);
}
return ans;
}
int main() {
ll x, y, n;
vector<ll> e1, e2;
scanf("%lld",&n);
while( n -- ) {
scanf("%lld%lld",&x,&y);
e1.push_back(x), e2.push_back(y);
}
printf("%lld\n",f(e1)+f(e2));
return 0;
}
Trace 2018徐州icpc网络赛 思维+二分的更多相关文章
- Trace 2018徐州icpc网络赛 (二分)(树状数组)
Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...
- Features Track 2018徐州icpc网络赛 思维
Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...
- Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...
- ICPC 2018 徐州赛区网络赛
ACM-ICPC 2018 徐州赛区网络赛 去年博客记录过这场比赛经历:该死的水题 一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. D. Easy Math 题意: ...
- ACM-ICPC 2018 徐州赛区(网络赛)
目录 A. Hard to prepare B.BE, GE or NE F.Features Track G.Trace H.Ryuji doesn't want to study I.Charac ...
- Supreme Number 2018沈阳icpc网络赛 找规律
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- 2019 徐州icpc网络赛 E. XKC's basketball team
题库链接: https://nanti.jisuanke.com/t/41387 题目大意 给定n个数,与一个数m,求ai右边最后一个至少比ai大m的数与这个数之间有多少个数 思路 对于每一个数,利用 ...
- Trace 2018徐州赛区网络预赛
题意: 每次给出一个点,然后就会形成两条线,如果后面的矩形覆盖了前面的边,那么这条边就消失了, 最后求剩下的边是多少 题目确保不会完全覆盖 也没有一个矩形在另一个矩形里面 即对于 X1,Y1 X2, ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
随机推荐
- TypeScript环境安装,以及配置idea开发环境
安装前准备 安装typescript需要用到npm管理工具,而npm是随同Node.js一起安装的包管理工具,所以要先安装Node 1.前往Node官网下载最新版安装包:http://nodejs.c ...
- 【iOS】设备系统版本
判断 iOS 系统的版本号,示例代码如下: NSLog(@"version--%d", [[[UIDevice currentDevice] systemVersion] floa ...
- 章节十五、5-记录日志---Log4j
一.为什么要用Log4j记录日志? 日志记录对于任何应用程序都非常重要. 它可以帮助我们快速调试代码,通过收集代码执行的信息让代码容易维护. 二.Log4j 是什么? Apache为Java提供的日志 ...
- ES 24 - 如何通过Elasticsearch进行聚合检索 (分组统计)
目录 1 普通聚合分析 1.1 直接聚合统计 1.2 先检索, 再聚合 1.3 扩展: fielddata和keyword的聚合比较 2 嵌套聚合 2.1 先分组, 再聚合统计 2.2 先分组, 再统 ...
- 微服务SpringCloud之Spring Cloud Config配置中心Git
微服务以单个接口为颗粒度,一个接口可能就是一个项目,如果每个项目都包含一个配置文件,一个系统可能有几十或上百个小项目组成,那配置文件也会有好多,对后续修改维护也是比较麻烦,就和前面的服务注册一样,服务 ...
- .Net Core in Docker - 使用阿里云Codepipeline及阿里云容器镜像服务实现持续集成(CI)
前面已经介绍过了 .Net Core 程序发布到 Docker 容器的内容.但是每次通过 SSH 链接到服务器敲命令,运行脚本也是挺麻烦的一件事.程序员是最懒的,能让电脑解决的问题绝不手动解决,如果当 ...
- JVM系列(3)- Java VisualVM使用
前言 Java VisualVM是jdk自带一款工具,可以十分友好的监控java进程相关的应用服务及中间件. 工具位置 jdk的bin目录下,找到jvisualvm.exe,双击打开即可. 功能介绍 ...
- [实践]redhat linux5.3安装tomcat
1.安装准备 操作系统:RedHat 5 (自带apache2.2.3) 安装tomcat前首先要安装jdk: 查看系统是否安装了jdk或tomcat的命令: rpm -qa | grep java ...
- Python基础总结之初步认识---class类的继承(终)。第十六天开始(新手可相互督促)
最近生病了,python更新要结束了,但是这才是真正的开始.因为后面要更新的是UnitTest单元测试框架,以及后续的Requests库.在后续的笔记会补充一些python的其他细节笔记.我想是这样的 ...
- 有关element 的一些问题(随时更新)
<el-input></el-input> input 组件中官方自带的change时间是监听失去焦点之后的value变化,要想一只监听value的值变化的话需要使用 @i ...