题目来源: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. Velocity 语法示例

    一.简介: 1)它允许任何人使用简单而强大的模板语言来引用定义在 java 代码中的对象" 2)Velocity是一个基于java的模板引擎,简称VTL(Velocity Template ...

  2. C#基础枚举的设计

    枚举分为:简单枚举和标记枚举(为了枚举值位操作) 标记枚举的用法:

  3. html5.边框属性相关知识点

    border-left 定义左边框 border-top 定义上边框 border-right 定义有边框 border-bottom 定义下边框 边框样式: dotted 边框线为点状虚线 dash ...

  4. Ring对象

    Ring是一个封闭的Path即起始和终止点有相同的坐标值,它有内部和外部属性.

  5. c - 每位数字尾部加空格

    /* input:一个4位整数. output:每位整数后紧跟一个空格的字符串. */ char * insert(char *s) { int len = strlen(s); * len + ); ...

  6. C#多态联系之虚方法

    class Class1 { static void Main(string[] args) { YuanGong yg = new YuanGong(); JingLi jl = new JingL ...

  7. (一)chrome扩展 - API小记

    browserAction 设置browser action的badge文字,badge 显示在图标上面 chrome.browserAction.setBadgeText({text:"i ...

  8. java部分基础总结

    新手期一些知识的总结面向对象: 首先先将面向对象与面向过程区分开:面向过程主要是通过过程,达到某种目的,这种目的的目标就是对象,二面向对象重点则是不再考虑过程,直接面向对象! 对象 概念:一切客观存在 ...

  9. C# HashSet类(复杂)对象的去重

    public class Student { public string Id { get; set; } public string Name { get; set; } public overri ...

  10. C程序设计语言练习题1-1

    练习1-1 在你自己的系统中运行"hello, world"程序.再有意去掉程序中的部分内容,看看会得到什么出错信息. 代码如下: #include <stdio.h> ...