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 ...
随机推荐
- 《数据通信与网络》笔记--虚电路网络:帧中继和ATM
在之前的文章中已经介绍过虚电路交换,详细请参见:http://blog.csdn.net/todd911/article/details/9069447 这边介绍下使用虚电路交换的2中WAN技术:帧中 ...
- 4.5 HOOK分发函数
4.5 HOOK分发函数 本节开始深入的探讨键盘的过滤与反过滤.有趣的是,无论是过滤还是反过 滤,其原理都是进行过滤.取胜的关键在于:谁将第一个得到信息. 黑客可能会通过修改一个已经存在的驱动对象(比 ...
- VS 2013--工程的创建,scanf报错,常用快捷键,行号设置
一.创建一个工程(这里是C++,其他的一样的) 在vs页面上点击 文件-->新建-->项目: 会出现如下界面,自己改名字和存贮位置就可以了 确定,然后点击下一步: 这样就建好了一个工程,然 ...
- CentOS 6 用SVN自动提交文件到web服务器
关于 svn 的安装 参考:[转]Linux(centOS6.5)下SVN的安装.配置及开机启动 经过两天的各种尝试总算解决了,总结如下: 1.在建立库时注意 要让库的名称和 要同步的 web目录名 ...
- Android ImageView(scaleType属性)图片按比例缩放
<ImageView android:id="@+id/img" android:src="@drawable/logo" android:scaleTy ...
- zk create() 方法
create() $path = $zkh->create($req_path, $data); $path = $zkh->create($req_path, $data, 'flags ...
- 模拟红外协议C程序——接收模块
目的:方便程序的调试,提供效率,减少工作累,可以不在线调试编程时显示实时数据,特别产品不带显示的或者MCU是OPT的,有很大的帮助. 过程:将要看的数据发送出来,另一个板(一个带有显示的就OK了,显示 ...
- Axis2(7):将Spring的装配JavaBean发布成WebService
在现今的Web应用中经常使用Spring框架来装载JavaBean.如果要想将某些在Spring中装配的JavaBean发布成WebService,使用Axis2的Spring感知功能是非常容易做到的 ...
- ExecuteReader: CommandText 属性尚未初始化
没有对sqlcommand对象的commandtext属性赋值说白了就是没写SQL语句 -.- 无语死了.
- Qt国际化相关类(以前没见过codec->toUnicode,QTextCodec,QLocale.toString和QLocale::setDefault,QInputMethod::locale())
QTextCodec QTextCodec为文本编码之间提供转换. Qt用Unicode 来存储,绘制和操作字符串.在很多情况下你可能希望操作不同编码的数据.例如,大部分日本文档是以Shift-JIS ...