日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[NOI2007]货币兑换

發布時間:2024/9/5 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [NOI2007]货币兑换 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

嘟嘟嘟

懶的寫博客了,恰好發現自己的思路跟某一老哥極其像,所以各位還是看這篇博客吧

寫的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]货币兑换的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。