SRM 582 Div II Level Two SpaceWarDiv2
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556
#include <iostream>
#include <vector>
#include <algorithm> using namespace std; int F[50]; class SpaceWarDiv2
{
public:
int minimalFatigue(vector <int> magicalGirlStrength, vector <int> enemyStrength, vector <int> enemyCount);
}; int SpaceWarDiv2::minimalFatigue(vector<int> magicalGirlStrength, vector<int> enemyStrength, vector<int> enemyCount)
{
int maxMS, maxES;
int i, j;
maxMS = *max_element(magicalGirlStrength.begin(), magicalGirlStrength.end());
maxES = *max_element(enemyStrength.begin(), enemyStrength.end());
if (maxMS < maxES) {
return -1;
} for (i = 0; i < 50; i++) {
F[i] = 0;
} sort(magicalGirlStrength.begin(), magicalGirlStrength.end()); for (i = 0; i < enemyStrength.size()-1; i++) {
for (j = i+1; j < enemyStrength.size(); j++) {
if (enemyStrength[i] > enemyStrength[j]) {
swap(enemyStrength[i], enemyStrength[j]);
swap(enemyCount[i], enemyCount[j]);
}
}
}
while (!enemyCount.empty()) {
for (i = 0; i < magicalGirlStrength.size(); i++) {
j = enemyStrength.size() - 1;
while (j >= 0 && magicalGirlStrength[i] < enemyStrength[j]) {
--j;
} if (j >= 0) {
++F[i];
--enemyCount[j];
if (0 == enemyCount[j]) {
enemyCount.erase(enemyCount.begin() + j);
enemyStrength.erase(enemyStrength.begin() + j);
}
}
}
} return *max_element(F, F + magicalGirlStrength.size());
}
SRM 582 Div II Level Two SpaceWarDiv2的更多相关文章
- SRM 582 Div II Level One: SemiPerfectSquare
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <ios ...
- SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意 ...
- SRM 223 Div II Level Two: BlackAndRed,O(N)复杂度
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3457&rd=5869 解答分析:http://comm ...
- SRM 207 Div II Level Two: RegularSeason,字符串操作(sstream),多关键字排序(操作符重载)
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=2866&rd=5853 主要是要对字符串的操作要熟悉,熟 ...
- SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2
题目来源: http://community.topcoder.com/tc?module=ProblemDetail&rd=15497&pm=12521 这个问题要注意的就是只需要直 ...
- SRM 583 Div II Level One:SwappingDigits
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609 #include <iostream> # ...
- SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...
- SRM 219 Div II Level One: WaiterTipping,小心约分
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609&rd=15503 这题目看上去so easy, ...
- SRM 212 Div II Level One: YahtzeeScore
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1692&rd=5858 比较简单. 代码如下: #inc ...
随机推荐
- php开启虚拟域名功能
1.开启apache的mod_rewrite功能 关闭注释 LoadModule rewrite_module modules/mod_rewrite.so 2.引入http-vhosts.conf文 ...
- Mirantis OpenStack HA
Mysql使用Galera做Active/Active集群,同时使用Pacemaker,因为Galera mysql用到了领导机选举机制quorum,所以控制节点至少三个 RabbitMQ使用mirr ...
- 多层TreeWidget可选实现
http://download.csdn.net/detail/lingyunfuyu2/9117481
- jquery删除动态增加的li
<script type="text/jscript"> //楼主帮你修改调整了下 $(document).ready(function () { $('.zuo li ...
- 设计模式 ( 十三 ) 命令模式Command(对象行为型)
设计模式 ( 十三 ) 命令模式Command(对象行为型) 1.概述 在软件设计中,我们经常需要向某些对象发送请求,但是并不知道请求的接收者是谁,也不知道被请求的操作是哪个,我们只需 ...
- Java 找出四位数的全部吸血鬼数字 基础代码实例
/** * 找出四位数的全部吸血鬼数字 * 吸血鬼数字是指位数为偶数的数字,能够由一对数字相乘而得到,而这对数字各包括乘积的一半位数的数字,当中从最初的数字中选取的数字能够随意排序. * 以两个 ...
- NDK如何调试系统核心动态库(无系统源码的情况)
版权归薛定諤耗子所有,转载请表明出处. 1,有源码,需要导入符号表 2,没有源码,如何调试 1)运行ndk-gdb:../../ndk-gdb --verbose --launch=com.examp ...
- POJ1700(过河问题)
#include<iostream> #include<algorithm> using namespace std; ]; int main() { int t,i; cin ...
- hdu4717 The Moving Points(二分做法)
这道题看了大家都是用三分做的,其实这道题也是可以用二分来做的,就是利用一下他们的单调性. 对于N个点,总共要考虑N(N+1)/2个距离,距离可以用二次函数表示,而且开口都是向上的. 下面具体说一下二分 ...
- VirtualBox安装及使用说明和虚拟机安装XP系统图文教程
virtualbox是一款开源的虚拟机软件,它能够支持多种操作系统的安装如:Solaris.Windows.DOS.Linux.OS/2 Warp.BSD等系统作为client操作系统,而且最新版本号 ...