标签:
每笔收入产生的收益是独立的。
计算所有点的收益率,累计。
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<vector> using namespace std; struct dd{ int d, e; }ndd[2505]; struct ddd{ int s, f, r; }mddd[2505]; bool dddcomp(ddd a, ddd b) { return a.s < b.s; } int rate[100005]; int max(int a, int b) { return a>b ? a : b; } int main() { int t, n, m; scanf("%d", &t); for (int w = 1; w <= t; ++w){ memset(rate, 0, sizeof(rate)); scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) scanf("%d %d", &ndd[i].d, &ndd[i].e); for (int i = 0; i < m; ++i) scanf("%d %d %d", &mddd[i].s, &mddd[i].f, &mddd[i].r); sort(mddd, mddd + m, dddcomp); //读取数据并排序 //求rate[],rate[i]=max(rate[i+1],rate[j]+r[i-j]),只需考虑 r[i-j]存在的情况 int pos = m - 1; for (int i = mddd[m - 1].s; i >= mddd[0].s; --i){ int mx = rate[i + 1]; while (pos >= 0 && i == mddd[pos].s){ mx = max(mx, mddd[pos].r + rate[mddd[pos].f]); --pos; } rate[i] = mx; } for (int i = mddd[0].s - 1; i >= 0; --i) rate[i] = rate[i + 1]; //分别计算收入的收益 long long sum = 0; for (int i = 0; i < n; ++i){ sum += rate[ndd[i].d] * ndd[i].e; } printf("Case #%d:\n%.2lf\n", w, (double)sum / 100.0); } }
标签:
原文地址:http://www.cnblogs.com/jokoz/p/4771399.html