牛客小白月赛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之后看了一下别人的题解,基本上都是线段树,不过二分也可以. 这个题目很自然就肯定要对其中一个进行排序,排完序之后再处理另外一边,另一边记得离散化. 怎么处理呢,你仔细想 ...
随机推荐
- html-其他常见标签的使用
b:加粗 s:删除线 u:下划线 i:斜体 per:原样输出 sup:上标 sub:下标 p:段落标签 比br多一行 (CSS) div:自动换行 span:在一行显示 完整代码: <html& ...
- ajax异步请求/同源策略/跨域传值
基本概念 Ajax 全称是异步的 JavaScript 和 XML . 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个网页的情况下,对网页的某部分进 ...
- Ckrule业务规则管理系统简介
1. 简述 Ckrule业务规则管理系统(BRMS)是一个集成的应用程序存储.管理.执行和测试的平台,允许组织定义.部署.监控和维护运营系统使用的各种复杂决策逻辑.Ckrule BRMS 独立于核 ...
- Android Proguard.flags LOCAL_PROGUARD_FLAGS
在Android项目中用到JNI,当用了proguard后,发现native方法找不到很多变量,原来是被produard优化掉了.所以,在JNI应用中该慎用progurad啊. 解决办法: 1.在An ...
- winform中 让 程序 自己重启
private void button1_Click(object sender, EventArgs e) { Application.ExitThread(); ...
- 实验,暂停oracle后台进程
有时出于测试需求,需要暂停oracle的某些后台进程,此时以暂停lgwr进程为例 使用sysdba连接到数据库查询到LGWR进程的PID:SQL> select prc.pid from v$b ...
- css渲染(三)颜色与背景
颜色的应用主要分为前景色.背景色和透明三个部分. 一.前景色 color color前景色 值: <color> | inherit 初始值: 用户代理特定的值 应用于: 所有元素 继承性 ...
- Django:ORM关系字段
一,ForeignKey 外键类型在ORM中用来表示外键关联关系,一般把ForeignKey字段设置在 '一对多'中'多'的一方. ForeignKey可以和其他表做关联关系同时也可以和自身做关联关系 ...
- BZOJ4566:[HAOI2016]找相同字符(SAM)
Description 给定两个字符串,求出在两个字符串中各取出一个子串使得这两个子串相同的方案数.两个方案不同当且仅当这两 个子串中有一个位置不同. Input 两行,两个字符串s1,s2,长度分别 ...
- HDU 5536 字典树
题意:就是公式. 这现场赛O(n^3)能过,觉得太没天理了. 做法:字典树,枚举两个数,然后在字典树上贪心的跑. #include <bits/stdc++.h> using namesp ...