牛客小白月赛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之后看了一下别人的题解,基本上都是线段树,不过二分也可以. 这个题目很自然就肯定要对其中一个进行排序,排完序之后再处理另外一边,另一边记得离散化. 怎么处理呢,你仔细想 ...
随机推荐
- windows环境下wampserver配置https
因为公司业务主要是在微信上进行开展的,所以作为程序员的我们每天的开发任务就都是在与微信打交道,这个时候我们就需要在本地配置端口映射到外网,方便我们在微信客户端进行调试. 最近某种需要,所以需要配置 h ...
- JQuery Tips
另一篇文章 JavaScript Tips 1. 获取span标签的值需要用text(); 2. datepicker控件的‘setDate’属性可用于设置默认值: 3. 使用parseFloat转换 ...
- ArcGIS Enterprise 10.5.1 静默安装部署记录(Centos 7.2 minimal)- 1、安装前准备
安装前准备 上传文件到服务器,x-ftp xshell登陆Centos 检查机器名 修改机器名为:portal.cloud.local 方法一:零时设置,重启后失效,该方法不可取 方法 ...
- 重复启动某一款应用,并传递intent参数
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName); intent.setFlags(Intent.F ...
- 树莓派3(Raspberry pi 3)刷OpenWrt
原文在 https://my.oschina.net/wangandi/blog/687389 1.下载镜像,这个lede好像是openwrt的一个分支,openwrt本身还没有支持pi3,https ...
- Excel数据导入Sql Server,部分数字为Null
在Excel中,我们时常会碰到这样的字段(最常见的就是电话号码),即有纯数字的(如没有带区号的电话号码),又有数字和其它字符混合 (如“区号-电 话号码”)的数据,在导入SQLServer过程中,会发 ...
- Mysql Order By 注入总结
前言 最近在做一些漏洞盒子后台项目的总结,在盒子多期众测项目中,发现注入类的漏洞占比较大.其中Order By注入型的漏洞也占挺大一部分比例,这类漏洞也是白帽子乐意提交的类型(奖金高.被过滤概率小). ...
- Python 列表(list)操作
创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...
- SpringMvc-helloword
说明:在此只说明helloword的简单实现,通过helloword例子先了解springMvc是这样工作的,然后在一步步的研究原理 配置web.xml 1.配置servlet servlet-cla ...
- day6-基础 模块详解
1.定义: 1)模块:本质上就是一个python程序,封装成一个"模块",可以调用里面的方法,用来实现一个功能.逻辑上用来组织python代码. 2)包:本质上是一个目录(必须带有 ...