题目来源: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的更多相关文章

  1. SRM 582 Div II Level One: SemiPerfectSquare

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <ios ...

  2. SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意  ...

  3. SRM 223 Div II Level Two: BlackAndRed,O(N)复杂度

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3457&rd=5869 解答分析:http://comm ...

  4. SRM 207 Div II Level Two: RegularSeason,字符串操作(sstream),多关键字排序(操作符重载)

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=2866&rd=5853 主要是要对字符串的操作要熟悉,熟 ...

  5. SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2

    题目来源: http://community.topcoder.com/tc?module=ProblemDetail&rd=15497&pm=12521 这个问题要注意的就是只需要直 ...

  6. SRM 583 Div II Level One:SwappingDigits

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609 #include <iostream> # ...

  7. SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...

  8. SRM 219 Div II Level One: WaiterTipping,小心约分

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609&rd=15503 这题目看上去so easy, ...

  9. SRM 212 Div II Level One: YahtzeeScore

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1692&rd=5858 比较简单. 代码如下: #inc ...

随机推荐

  1. iOS中的图像处理(三)——混合运算

    有时候,单独对一张图像进行处理是很难或者根本达不到我们想要的效果的.一个好的滤镜效果的诞生,往往要经过很多复杂步骤.细致微调.图片应用效果观察以及很多图层叠加. 我在JSWidget上发现了一些常用混 ...

  2. JS+CSS打造三级折叠菜单,自动收缩其它级 js

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...

  3. CMarkUp接口说明

    CMarkup是一个小型XML的分析器,实现语言是C++,英文版的接口说明地址为:http://www.firstobject.com/dn_markupmethods.htm 有厉害的网友已经翻译出 ...

  4. Hibernate 笔记1

    Hibernate表generator标签的作用,如下图,

  5. ArcEngine 图层无闪烁刷新

    使用AE的同行经常会遇到这样的问题,图层刷新.目前常用的有以下几种方法: 1.完全刷新 MapControl.Refresh(); 2.局部刷新 MapControl.Refresh(esriView ...

  6. 【集训笔记】二分图及其应用【HDOJ1068【HDOJ1150【HDOJ1151

    匈牙利算法样例程序 格式说明 输入格式: 第1行3个整数,V1,V2的节点数目n1,n2,G的边数m 第2-m+1行,每行两个整数t1,t2,代表V1中编号为t1的点和V2中编号为t2的点之间有边相连 ...

  7. django 时间计数

    value必须replace(tzinfo=None)变成datetime格式,否则格式不对不能相减.

  8. CreateFile函数使用方法详细介绍

    CreateFileThe CreateFile function creates or opens the following objects and returns a handle that c ...

  9. HDU 4679 String

    String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Sub ...

  10. 一步一步重写 CodeIgniter 框架 (5) —— 实现Controller,并加载Model

    CodeIgniter 框架采用MVC模式,而MVC模式中起纽带作用的就是C(控制器),在控制器的中通过加载模型获得数据,将数据传到视图中进行展示.本课将实现在控制器中加载模型. 1. 控制器的实现 ...