题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12707

算法决定一切,这道题目有很多方法解,个人认为这里 vexorian 给出的解法最简便,编码也最容易。而使用brute force 和 DP都比较复杂。

代码如下:

#include <algorithm>
#include <iostream>
#include <sstream> #include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map> #include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring> using namespace std; /*************** Program Begin **********************/ class GUMIAndSongsDiv2 {
public:
int maxSongs(vector <int> duration, vector <int> tone, int T) {
int res = 0;
int N = duration.size(); vector <int> songs;
for (int i = 0; i < N; i++) {
for (int j = i; j < N; j++) {
int maxTone = max(tone[i], tone[j]);
int minTone = min(tone[i], tone[j]);
songs.clear();
for (int k = 0; k < N; k++) {
if (tone[k] <= maxTone && tone[k] >= minTone) {
songs.push_back(duration[k]);
}
}
sort(songs.begin(), songs.end());
int sum = 0;
int c = 0;
for (int k = 0; k < songs.size(); k++) {
sum += songs[k];
if (sum <= T - maxTone + minTone) {
++c;
}
}
res = max(res, c);
}
} return res;
}
}; /************** Program End ************************/

SRM 588 D2 L2:GUMIAndSongsDiv2,冷静思考,好的算法简洁明了的更多相关文章

  1. SRM 588 D2 L3:GameInDarknessDiv2,DFS

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12710 采用DFS搜索,第一次写的时候忘了加访问标志,结果状态 ...

  2. SRM 581 D2 L2:SurveillanceSystem,重叠度

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12588 在判断 ‘+’ 的时候使用了 重叠度 的概念,跟一般的 ...

  3. SRM 588 DIV1

    250 题意:有n首不同的曲子,你唱每首曲子需要花费a的时间以及一个调整的时间b,调整的时间为此首歌的曲调减去上一首歌的曲调的绝对值. 思路:我们用dp[i][k]表示前i首歌只唱k首用的最小时间花费 ...

  4. TopCoder SRM 588 DIV2 KeyDungeonDiv2

    简单的题目 class KeyDungeonDiv2 { public: int countDoors(vector <int> doorR, vector <int> doo ...

  5. SRM 620 DIV1 L2

    题意:有n个等长的string(设string的长度为m),string中的字符从'A'到'Z',容许对m列执行稳定的排序操作,问说是否能通过这m种操作将这n个string调整成对应的顺序. 题解: ...

  6. SRM 585 DIV1 L2

    记录dp(i, j)表示前i种卡片的排列,使得LISNumber为j的方法数. #include <iostream> #include <vector> #include & ...

  7. SRM 581 D2 L3:TreeUnionDiv2,Floyd算法

    题目来源:http://community.topcoder.com//stat?c=problem_statement&pm=12587&rd=15501 这道题目开始以为是要在无向 ...

  8. Codeforces Global Round 7 D2. Prefix-Suffix Palindrome (Hard version)(Manacher算法)

    题意: 取一字符串不相交的前缀和后缀(可为空)构成最长回文串. 思路: 先从两边取对称的前后缀,之后再取余下字符串较长的回文前缀或后缀. #include <bits/stdc++.h> ...

  9. Codeforces Global Round 7 D2. Prefix-Suffix Palindrome (Hard version)(Manacher算法+输出回文字符串)

    This is the hard version of the problem. The difference is the constraint on the sum of lengths of s ...

随机推荐

  1. Android事件处理之多点触摸与手势识别

    一.Muilti-touch 双指缩放的实现探索: 首先要实现OnTouchListener接口,然后重写方法: public boolean onTouch(View v, MotionEvent ...

  2. Adobe/Flash Media Server 5.0 linux 64位系统下的安装

    一.下载 Adobe/Flash MS5.0下载地址: http://fs1.d-h.st/download/00036/VOt/adobemediaserver_5_ls1_linux64.tar. ...

  3. HashMap的分析(转)

    一.HashMap概述 HashMap基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了不同步和允许使用 null 之外,HashMap  ...

  4. 知问前端--Ajax

    本节课主要是创建一个问题表,将提问数据通过 ajax 方式提交出去.然后对内容显示进行布局,实现内容部分隐藏和完整显示的功能. 一.Ajax 提问创建一个数据表:question,分别建立:id.ti ...

  5. Win8 弹出窗口不在最前端的解决方法

    Win8系统的使用者有很多会遇到弹出窗口不在最前端的情况(自动隐藏,点下页面又出来),比如另存为的时候 ,或是登录路由器时弹出的登录框时. 引起这个异常的原因是与系统输入法冲突引起,但又不可能不用第三 ...

  6. django: startproject

    python 的 django 框架的安装教程很多,这里不列举安装过程,直接开始记开发应用过程. 1  startprojec,新建项目 $ django-admin.py startproject ...

  7. bootstrap table使用小记

    bootstrap table是一个非常不错的,基于bootstrap的插件,它扩展和丰富了bootstrap表格的操作,如格式化表格,表格选择器,表格工具栏,分页等等. 最近基于bootstrap开 ...

  8. WPF DataGrid 之数据绑定

    1. Auto generation of columns 最简单的方法莫过于让DataGrid根据数据源中的字段自动生成列了: 根据实体类的公共属性, 能够自动生成四种类型的数据列,对应关系如下: ...

  9. 触发器内insert,delete,update判断执行不同的内容

    create trigger tr_aon afor insert,update,delere asbegin IF EXISTS(SELECT 1 FROM inserted) AND NOT EX ...

  10. iOS开发中的MVC设计模式

    我们今天谈谈cocoa程序设计中的 模型-视图-控制器(MVC)范型.我们将从两大方面来讨论MVC: 什么是MVC? M.V.C之间的交流方式是什么样子的? 理解了MVC的概念,对cocoa程序开发是 ...