嘟嘟嘟

懒的写博客了,恰好发现自己的思路跟某一老哥极其像,所以各位还是看这篇博客吧

写的CDQ分治,感觉不是很懂,以后还得再复习一遍。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e5 + 5;
inline ll read()
{ll ans = 0;char ch = getchar(), last = ' ';while(!isdigit(ch)) {last = ch; ch = getchar();}while(isdigit(ch)) {ans = (ans << 1) + (ans << 3) + ch - '0'; ch = getchar();}if(last == '-') ans = -ans;return ans;
}
inline void write(ll x)
{if(x < 0) x = -x, putchar('-');if(x >= 10) write(x / 10);putchar(x % 10 + '0');
}int n;
db s, a[maxn], b[maxn], rat[maxn];
int q[maxn], qry[maxn];inline bool cmp(int i, int j)
{return a[i] * b[j] < a[j] * b[i];
}db dp[maxn], ans = 0;
struct Point
{db x, y;inline bool operator < (const Point& oth)const{return x < oth.x || (x == oth.x && y < oth.y);}
}p[maxn], que[maxn];inline bool slope(Point k, Point j, Point i)
{return (j.x - i.x) * (k.y - i.y) - (j.y - i.y) * (k.x - i.x) <= 0;
}
inline db calc(Point j, int i)
{return j.x * a[i] + j.y * b[i];
}inline void cdqSolve(int L, int R)
{if(L == R){if(dp[L - 1] > dp[L]) dp[L] = dp[L - 1];p[L].y = dp[L] / (rat[L] * a[L] + b[L]);p[L].x = rat[L] * p[L].y;return;}int mid = (L + R) >> 1, id1 = L, id2 = mid + 1, l = 1, r = 0;for(int i = L; i <= R; ++i) q[qry[i] <= mid ? id1++ : id2++] = qry[i];for(int i = L; i <= R; ++i) qry[i] = q[i];cdqSolve(L, mid);for(int i = L; i <= mid; ++i){while(r > 1 && slope(que[r - 1], que[r], p[i])) --r;que[++r] = p[i];}for(int i = mid + 1; i <= R; ++i){int j = qry[i];while(l < r && calc(que[l], j) <= calc(que[l + 1], j)) ++l;dp[j] = max(dp[j], calc(que[l], j));}cdqSolve(mid + 1, R);if(L == 1 && R == n) return;l = id1 = L; id2 = mid + 1;while(l <= R){if(id2 > R || (id1 <= mid && p[id1] < p[id2])) que[l++] = p[id1++];else que[l++] = p[id2++];}for(int i = L; i <= R; ++i) p[i] = que[i];return;
}int main()
{n = read(); scanf("%lf", &s);for(int i = 1; i <= n; ++i) scanf("%lf%lf%lf", &a[i], &b[i], &rat[i]), qry[i] = i;sort(qry + 1, qry + n + 1, cmp);dp[0] = s;cdqSolve(1, n);printf("%.3lf\n", dp[n]);return 0;
}

转载于:https://www.cnblogs.com/mrclr/p/10132644.html

[NOI2007]货币兑换相关推荐

  1. bzoj千题计划237:bzoj1492: [NOI2007]货币兑换Cash

    http://www.lydsy.com/JudgeOnline/problem.php?id=1492 dp[i] 表示 第i天卖完的最大收益 朴素的dp: 枚举从哪一天买来的在第i天卖掉,或者是不 ...

  2. 【BZOJ1492】[NOI2007]货币兑换Cash 斜率优化+cdq分治

    [BZOJ10492][NOI2007]货币兑换Cash Description 小Y最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A纪念券(以下简称A券)和 B纪念券(以下简称B券).每 ...

  3. 【bzoj 1492】【codevs 1797】 [NOI2007]货币兑换Cash (dp+cdq分治)

    1492: [NOI2007]货币兑换Cash Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 3803  Solved: 1604 [Submit][S ...

  4. P4027 [NOI2007] 货币兑换

    P4027 [NOI2007] 货币兑换 题目描述 小 Y 最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A 纪念券(以下简称 A 券)和 B 纪念券(以下简称 B 券).每个持有金券的顾 ...

  5. [BZOJ1492] [NOI2007]货币兑换Cash 斜率优化+cdq/平衡树维护凸包

    1492: [NOI2007]货币兑换Cash Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 5907  Solved: 2377 [Submit][S ...

  6. BZOJ 1492: [NOI2007]货币兑换Cash [CDQ分治 斜率优化DP]

    传送门 题意:不想写... 扔链接就跑 好吧我回来了 首先发现每次兑换一定是全部兑换,因为你兑换说明有利可图,是为了后面的某一天两种卷的汇率差别明显而兑换 那么一定拿全利啊,一定比多天的组合好 $f[ ...

  7. NOI2007 货币兑换 - CDQ分治斜率优化dp

    斜率优化dp维护一个凸壳.如果\(x, y\)坐标都递增,可以用单调队列,如果只有\(x\)递增,可以在凸壳上二分斜率,如果\(x, y\)都不递增,则需要在凸包中插入,可以用平衡树或cdq分治维护. ...

  8. bzoj1492: [NOI2007]货币兑换Cash

    码了我两个星期的题啊,终于写完了,感觉一半的时间都在调splay,后面写cdq好像轻松一点,cdq码量小一倍,而且又好想(可能是我调的时候理解了)感觉这种黑科技很nb,关键是可以减少细节出错(像我这种 ...

  9. [NOI2007]货币兑换Cash(DP+动态凸包)

    第一次打动态凸包维护dp,感觉学到了超级多的东西. 首先,set是如此的好用!!!可以通过控制一个flag来实现两种查询,维护凸包和查找斜率k 不过就是重载运算符和一些细节方面有些恶心,90行解决 后 ...

  10. [NOI2007] 货币兑换 解题报告

    https://www.zybuluo.com/rebirth1120/note/1528243 转载于:https://www.cnblogs.com/BruceW/p/11315368.html

最新文章

  1. 《网站设计 开发 维护 推广 从入门到精通》—— 2.3 页面设计创意思维
  2. wxWidgets:wxSocketBase类用法
  3. 【转】C#调用WebService实例和开发
  4. C#知识点总结系列:C# 数据结构
  5. 远程访问rest方式
  6. doxygen问题集锦
  7. linux bash 历史记录,Linux Bash History 命令历史记录
  8. mfc ctabctrl 双排显示_盐城便宜的开口型双排脚手架生产厂家-斯戴博盘扣脚手架...
  9. Python语法之com[1][:-7]
  10. c++ primer练习题 第七章 类 (Class)
  11. 如何正确使用日志Log
  12. 【IBM Tivoli Identity Manager 学习文档】3 基本架构
  13. 无需备份!!!动态磁盘转换为基本磁盘!!!绝对可用!!!
  14. linux 模拟手机浏览器,Firefox模拟手机浏览器(iOS+Android) – UserAgent Switcher使用方法...
  15. 内存与硬盘读取速度对比
  16. 「Adobe国际认证」Adobe Photoshop,如何裁剪并拉直照片?
  17. Windows部署solr服务,启动solr单机模式和solrCould模式
  18. 点连线的思路与js的简单实现
  19. ubuntu依赖库下载(pkgs)
  20. 采用α-β算法实现井字棋游戏

热门文章

  1. linux下截取安卓手机屏幕,截取屏幕截图
  2. js排序的时间复杂度_经典排序方法的python实现和复杂度分析
  3. java判断对象无数据_java利用反射机制判断对象的属性是否为空以及获取和设置该属性的值...
  4. @RequestBody注解分析
  5. 中国大学moocpython笔记_用Python玩转数据,中国大学MOOC(慕课)答案公众号搜题
  6. readfile读取串口数据_西门子PLC-1200-串口Modbus RTU通讯实例
  7. phpstorm遍历PHP数组,使用PHPStorm对齐数组的键值对
  8. torchvision0.2.2_Xcode 10.2
  9. Hive 内部表与外部表
  10. 二十四、TextCNN的原理和实现