Best Financing(HD4833)
每笔收入产生的收益是独立的。
计算所有点的收益率,累计。
- #define _CRT_SECURE_NO_WARNINGS
- #include<iostream>
- #include<algorithm>
- #include<vector>
- using namespace std;
- struct dd{
- int d, e;
- }ndd[];
- struct ddd{
- int s, f, r;
- }mddd[];
- bool dddcomp(ddd a, ddd b)
- {
- return a.s < b.s;
- }
- int rate[];
- int max(int a, int b)
- {
- return a>b ? a : b;
- }
- int main()
- {
- int t, n, m;
- scanf("%d", &t);
- for (int w = ; w <= t; ++w){
- memset(rate, , sizeof(rate));
- scanf("%d %d", &n, &m);
- for (int i = ; i < n; ++i)
- scanf("%d %d", &ndd[i].d, &ndd[i].e);
- for (int i = ; 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 - ;
- for (int i = mddd[m - ].s; i >= mddd[].s; --i){
- int mx = rate[i + ];
- while (pos >= && i == mddd[pos].s){
- mx = max(mx, mddd[pos].r + rate[mddd[pos].f]);
- --pos;
- }
- rate[i] = mx;
- }
- for (int i = mddd[].s - ; i >= ; --i)
- rate[i] = rate[i + ];
- //分别计算收入的收益
- long long sum = ;
- for (int i = ; 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)的更多相关文章
- HDU 4833 Best Financing(DP)(2014年百度之星程序设计大赛 - 初赛(第二轮))
Problem Description 小A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在第dates[ ...
- HDU 4833 Best Financing (DP)
Best Financing Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu4833 Best Financing(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4833 这道题目关键的思想是从后往前dp,dp[i]表示在第i处投资xi能获得的最大收益,其中xi表示从 ...
- Translate Exercises(4)
周五翻译课记录. ---------------------------------- (1)and it is imagined by many that the operations of the ...
- (原创)北美信用卡(Credit Card)个人使用心得与总结(个人理财版) [精华]
http://forum.chasedream.com/thread-766972-1-1.html 本人2010年 8月F1 二度来美,现在credit score 在724-728之间浮动,最高的 ...
- Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求
上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...
- Angular2学习笔记(1)
Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...
- ASP.NET Core 之 Identity 入门(一)
前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
随机推荐
- [Math]Sqrt(x)
Total Accepted: 75767 Total Submissions: 314003 Difficulty: Medium Implement int sqrt(int x). Comput ...
- CDZSC_2015寒假新人(1)——基础 e
Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever ...
- spring注解注入:<context:component-scan>使用说明
spring从2.5版本开始支持注解注入,注解注入可以省去很多的xml配置工作.由于注解是写入java代码中的,所以注解注入会失去一定的灵活性,我们要根据需要来选择是否启用注解注入. 在XML中配置了 ...
- eclipse 常用的一些设置
1.行长度设置 http://blog.csdn.net/janronehoo/article/details/10047937 2.字体 windows -> preference -> ...
- TComponent与String的转换(得到控件的DFM格式的描述)
现看下面这两个方法,把一个TComponent做成String,再就是把String转成TComponent function ComponentToStringProc(Component: TCo ...
- android HttpGet 另开线程获取网络数据问题
android跨线程通讯可以使用android.os.Handler-android.os.Message这两类对象完成. public static void getResultForHttpGet ...
- java中HashSet实现(转)
hashset底层的数据结构是hash表,hash表实现方式采用数组+链表,数组类型为HashNode,每个数组元素为链表的头指针,链表中存储经过hash函数散列后冲突的元素,数组的长度为26 has ...
- stl入门--reverse函数
#include<iostream> #include<algorithm> using namespace std; int main() { ch ...
- linux 启动 oracle数据库
第一步:切换到oracle用户 su - oracle 第二步:启动oracle数据库监听 lsnrctl start 第三步:输入下方命令,出现:sql> sqlplus /nolog 第四步 ...
- [笔记] /etc/init.d/ 下脚本的通用结构
http://sunxiaqw.blog.163.com/blog/static/99065438201111715813443/ 下面以 named 为例 : #!/bin/bash # # nam ...