题目来源: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. CSDN排名第一和第二的人

    http://blog.csdn.net/phphot http://blog.csdn.net/yuanmeng001

  2. c#关于委托和事件

    using System; using System.Collections.Generic; using System.Text; namespace Delegate {     // 热水器   ...

  3. 移动端rem,scale动态设置

    pt:物理像素(电容屏上像素块个数) px:逻辑像素.设备独立像素 高清屏:1px = 4pt 普通屏:1px = 1pt dpr:设备像素比:(某一方向上)物理像素/逻辑像素 通常设置1rem=屏幕 ...

  4. hdu 4784 Dinner Coming Soon

    spfa+优先队列.刚开始只用的spfa,结果tle到死.然后听队友说要用到优先队列,想了想,对时间分层的话的确每一个结点都只进队列一次即可,因为只有大时间才能更新出小时间,然后就wa成shi了.按队 ...

  5. Linux下通过rm -f删除大量文件时提示"-bash: /bin/rm: Argument list too long"的解决方法

    Linux下通过rm -f删除/var/spool/postfix/maildrop/中大量的小文件时提示: "-bash: /bin/rm: Argument list too long& ...

  6. 二维码类库--phpqrcode使用简介

    #载入类文件 include 'phpqrcode.php'; $value = '二维码内容'; $errorCorrectionLevel = 'L';//容错级别 L.M.Q.H $matrix ...

  7. QSplashScreen无法背景透明的解决办法(强制StyleSheet生效)

    setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen | Qt::FramelessWindowHint); setAttribute( ...

  8. cocos2dx进阶学习之CCObject

    继承关系 CCObject -> CCCopying 类定义 class CC_DLL CCObject : public CCCopying { public: // object id, C ...

  9. [转]php连接postgresql

    首先推荐一下postgres数据库,免费,强大,甚至某些方面比商业数据库还要好,大家可以试试. 安装: 附安装图解(网上找的):http://blog.sina.com.cn/s/blog_5edb7 ...

  10. HDOJ 1005

    Input The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a ...