牛客小白月赛2 I 艺 【归并思想】【离散化】
链接:https://www.nowcoder.com/acm/contest/86/I
来源:牛客网
题目描述
输入描述:
输出描述:
输出共一行,一个整数,表示最大的愉悦度。
输入例子:
2 2 5
2 3
0 2
0 3
3 1
输出例子:
15
-->
备注:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector> using namespace std; #define max3(x, y, z) max(max((x), (y)), (z))
#define min3(x, y, z) min(mix((x), (y)), (z))
#define pb push_back
#define ppb pop_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<long long, long long> #define debug_l(a) cout << #a << " " << (a) << endl
#define debug_b(a) cout << #a << " " << (a) << " "
#define testin(filename) freopen((filename) ,"r",stdin)
#define testout(filename) freopen((filename) ,"w",stdout) #define close_sync (ios::sync_with_stdio(false)) typedef long long ll;
typedef unsigned long long ull; const double PI = 3.14159265358979323846264338327;
const double E = exp();
const double eps = 1e-; const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
// int maxn = 3e3 + 5;
// int MOD = 1e9 + 7; template <typename T>
void print_arr(T *arr, int arr_len)
{
for (int i = ; i < arr_len; i++)
cout << arr[i] << " ";
cout << endl;
} /*==================================begin=======================================*/ const int maxn = 1e5+;
struct Node {int x,v;};
Node f[maxn],s[maxn];
int cmp(Node n1, Node n2){
return n1.x<n2.x;
}
int main()
{
// testin("data.in");
close_sync;
int N,M,T;
cin>>N>>M>>T;
for(int i=;i<N;i++) cin>>f[i].x>>f[i].v;
for(int i=;i<M;i++) cin>>s[i].x>>s[i].v;
sort(f,f+N,cmp); sort(s,s+M,cmp); f[N].x=s[M].x=T; //关键,在遍历到数组最后一个元素的时候,下一个值是结束时间。从而计算权值 int i=,j=,t=,nt;
ll ans=;
while(i<N && j<M){
if(f[i].x<=t) i++;
if(s[j].x<=t) j++;
nt= min(f[i].x,s[j].x);
ans+=(nt-t)*max3(,f[i-].v,s[j-].v);
t=nt;
}
while(i<N){
if(f[i].x<=t) i++;
ans+=(f[i].x-t)*max3(,f[i-].v,s[j-].v);
t=f[i].x;
}
while(j<M){
if(s[j].x<=t) j++;
ans+=(s[j].x-t)*max3(,f[i-].v,s[j-].v);
t=s[j].x;
}
cout<<ans<<endl;
return ;
}
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector> using namespace std; #define max3(x, y, z) max(max((x), (y)), (z))
#define min3(x, y, z) min(mix((x), (y)), (z))
#define pb push_back
#define ppb pop_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<long long, long long> #define debug_l(a) cout << #a << " " << (a) << endl
#define debug_b(a) cout << #a << " " << (a) << " "
#define testin(filename) freopen((filename) ,"r",stdin)
#define testout(filename) freopen((filename) ,"w",stdout) #define close_sync (ios::sync_with_stdio(false)) typedef long long ll;
typedef unsigned long long ull; const double PI = 3.14159265358979323846264338327;
const double E = exp();
const double eps = 1e-; const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
// int maxn = 3e3 + 5;
// int MOD = 1e9 + 7; template <typename T>
void print_arr(T *arr, int arr_len)
{
for (int i = ; i < arr_len; i++)
cout << arr[i] << " ";
cout << endl;
} /*==================================begin=======================================*/
const int maxn = 1e5+;
struct Node
{
int x,v;
}; Node f[maxn],s[maxn]; int cmp(Node n1, Node n2){
return n1.x<n2.x;
} void print_arr(Node a[],int n){
for(int i=;i<n;i++)
cout<<"("<<a[i].x<<","<<a[i].v<<")";
cout<<endl;
} int main()
{
//testin("data.in");
close_sync;
int N,M,T;
cin>>N>>M>>T;
for(int i=;i<N;i++) cin>>f[i].x>>f[i].v;
for(int i=;i<M;i++) cin>>s[i].x>>s[i].v;
sort(f,f+N,cmp); sort(s,s+M,cmp); // print_arr(f,N);print_arr(s,M); set<int> ss;
for(int i=;i<N;i++) ss.insert(f[i].x);
for(int i=;i<M;i++) ss.insert(s[i].x);
ss.insert(T); // for(set<int>::iterator it=ss.begin();it!=ss.end();++it)
// cout<<*it<<" ";
// cout<<endl; f[N].x=T;f[N].v=f[N-].v;
s[M].x=T;s[M].v=s[M-].v; set<int>::iterator it=ss.begin();
ll ans=;
for(int i=,j=,t=;t<T;){
while(i+<N+ && f[i+].x<=t) i++;
while(j+<M+ && s[j+].x<=t) j++;
ans+=(*(++it)-t)*(max3(f[i].v,s[j].v,));
// debug_b(t),debug_b(*it),debug_b(max3(f[i].v,s[j].v,0)),debug_b(i),debug_l(j);
t=*it;
}
cout<<ans<<endl; return ;
}
牛客小白月赛2 I 艺 【归并思想】【离散化】的更多相关文章
- 树的最长链-POJ 1985 树的直径(最长链)+牛客小白月赛6-桃花
求树直径的方法在此转载一下大佬们的分析: 可以随便选择一个点开始进行bfs或者dfs,从而找到离该点最远的那个点(可以证明,离树上任意一点最远的点一定是树的某条直径的两端点之一:树的直径:树上的最长简 ...
- 牛客网 牛客小白月赛5 I.区间 (interval)-线段树 or 差分数组?
牛客小白月赛5 I.区间 (interval) 休闲的时候写的,但是写的心情有点挫,都是完全版线段树,我的一个队友直接就水过去了,为啥我的就超内存呢??? 试了一晚上,找出来了,多初始化了add标记数 ...
- 牛客小白月赛8 - E - 诡异数字 数位DP
牛客小白月赛8 - E - 诡异数字 题意: 求区间中,满足限制条件的数字的个数. 限制条件就是某些数字不能连续出现几次. 思路: 比较裸的数位DP, DP数组开一个dp[len][x][cnt] 表 ...
- 牛客小白月赛18 Forsaken给学生分组
牛客小白月赛18 Forsaken给学生分组 Forsaken给学生分组 链接:https://ac.nowcoder.com/acm/contest/1221/C来源:牛客网 Forsaken有 ...
- 牛客小白月赛18 Forsaken喜欢数论
牛客小白月赛18 Forsaken喜欢数论 题目传送门直接点标题 Forsaken有一个有趣的数论函数.对于任意一个数xxx,f(x)f(x)f(x)会返回xxx的最小质因子.如果这个数没有最小质 ...
- 牛客小白月赛19 E 「火」烈火燎原 (思维,树)
牛客小白月赛19 E 「火」烈火燎原 (思维,树) 链接:https://ac.nowcoder.com/acm/contest/2272/E来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空 ...
- 【牛客小白月赛21】NC201604 Audio
[牛客小白月赛21]NC201604 Audio 题目链接 题目大意: 给出三点 ,求到三点距离相等的点 的坐标. 解析 考点:计算几何基础. 初中蒟蒻表示不会什么法向量.高斯消元..qwq 方法一: ...
- 【牛客小白月赛21】NC201605 Bits
[牛客小白月赛21]NC201605 Bits 题目链接 题目描述 Nancy喜欢做游戏! 汉诺塔是一个神奇的游戏,神奇在哪里呢? 给出3根柱子,最开始时n个盘子按照大小被置于最左的柱子. 如果盘子数 ...
- 牛客小白月赛16 小石的妹子 二分 or 线段树
牛客小白月赛16 这个题目我AC之后看了一下别人的题解,基本上都是线段树,不过二分也可以. 这个题目很自然就肯定要对其中一个进行排序,排完序之后再处理另外一边,另一边记得离散化. 怎么处理呢,你仔细想 ...
随机推荐
- Linux的find命令实例详解和mtime ctime atime
这次解释一下三个Linux文件显示的三个时间,然后展示一下find命令的各个功能 在linux操作系统中,每个文件都有很多的时间参数,其中有三个比较主要,分别是ctime,atime,mtime mo ...
- 为 Drupal 7 构建一个新主题
主题解释了 Drupal 网站的用户界面 (UI).虽然主题结构并没有明显的变化,但 Drupal 版本 7 配备了一个新的主题实现方法.本文演示了如何创建一个新的 Drupal 7 主题. Drup ...
- SharePoint 2013 - Sideloading
默认情况下,App是不能直接部署到Production环境,只能通过App Catalog中安装. 只有在Developer类型站点中才默认激活了Developer feature. 所以如果想要使用 ...
- 【起航计划 033】2015 起航计划 Android APIDemo的魔鬼步伐 32 App->Service->Foreground Service Controller service使用,共享service,前台服务,onStartCommand
Android系统也提供了一种称为“Service”的组件通常在后台运行.Activity 可以用来启动一个Service,Service启动后可以保持在后台一直运行,即使启动它的Activity退出 ...
- Siebel界面的搭建
Siebel界面的初步搭建都是基于Siebel Tools工具来创建的,其搭建步骤: 1. 首先先创建一个Project项目,点击project--->点 new Record--->输入 ...
- Consul在linux系统, 群集实战
Consul作为微服务的服务注册与发现组件,是非常重要的一部分 目前想用Consul作为配置管理的统一管理 准备两台机器 11.11.11.1011.11.11.20 下载consul linux版 ...
- FileHelpers 用法 z
用FileHelplers导出csv数据: [DelimitedRecord(",")] [IgnoreEmptyLines()] [ConditionalRecord(Recor ...
- 从零搭建docker+jenkins 自动化部署环境
从零搭建docker+jenkins+node.js自动化部署环境 本次案例基于CentOS 7系统 适合有一定docker使用经验的人阅读 适合有一定linux命令使用经验的人阅读 1.docker ...
- C#转Java之路之三:多线程并发容器即线程安全的容器
CopyOnWriteArrayList 和 CopyOnWriteArraySet: 是java中两个比较重要的并发容器.适用于读多于写的场景,且集合数据不太大的场合. 特别是CopyOnWrite ...
- March 26 2017 Week 13 Sunday
Deliver not your words by number but by weight. 言不在多,而在有物. Do more than talk, say something. I still ...