题目来源: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. XML解析器(TinyXML)的使用指南

    关于XML文件的解析方法的引导, 大家可以去试试这个工具(TinyXML) 1.首先下载TinyXML库的文件,这里给出链接,大家自己去下吧,记着要上国际http://prdownloads.sour ...

  2. 对return 语句的正确性和效率进行检查

    注意事项如下: 1. return 语句不可返回指向"堆栈内存“的”指针“或者”引用“,因为该内存单元在函数体结束时被自动释放. //错误 char* Func(void) { char s ...

  3. springmvc入门详解

    首先,我们先写一个入门小案例,先熟悉一下springmvc是什么,了解一下springmvc的运行流程,对加强springmvc的深层理解有很大帮助 .第一步,创建一个maven项目: <?xm ...

  4. SplitButton( 分割按钮)

    一. 加载方式//class 加载方式<a href="javascript:void(0)" id="edit" class="easyui- ...

  5. 打开新窗口(window.open)

    open() 方法可以查找一个已经存在或者新建的浏览器窗口. 语法: window.open([URL], [窗口名称], [参数字符串]) 参数说明: URL:可选参数,在窗口中要显示网页的网址或路 ...

  6. Objective-C 异常处理

    #import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char * argv[]) { ...

  7. 基于live555的一个简单RTSP服务器

    1,编译live555源码目录下的 BasicUsageEnvironment.groupsock.liveMedia.UsageEnvironment四个工程生成相应的库文件: 目录结构如下: 2, ...

  8. AD DIV 层的知识 和 行为特效

    1.AP(绝对定位) 2.使用AP DIV层和表格结合起来完美布局网页 3.层的Z轴值越大,该层就位于比较顶的位置 4.层有可见性的属性,层溢出,层的裁剪, 5层嵌套,先把光标定位在外层里面,然后拖多 ...

  9. Python基础第三天

    三元运算 三元运算又叫三目运算,是对简单的条件语句的缩写,例如if判断 # 标准if判断语法 if 1 == 1: name = "yes" else: name = " ...

  10. Python核心编程(第八章)--条件和循环

    如果一个复合语句(if子句,while或for循环)的代码仅仅包含一行代码,可以和前面的语句写在同一行上:   elif语句(else-if) 条件表达式(三元操作符) X if C else Y 计 ...