Best Financing(HD4833)

來源:互聯網
上載者:User

標籤:

每筆收入產生的收益是獨立的。

計算所有點的收益率,累計。

#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);    }}

 

Best Financing(HD4833)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.