1001 Senior's Array

题目链接:1001

题意:给你一个长度为n的序列,你必须修改序列中的某个数为P,求修改后的最大连续子序列和。

思路:数据量比较小,可以直接暴力做, 枚举序列的每个数修改成P,然后更新最大子序列和。

code:

 #include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = ;
typedef long long LL;
int a[MAXN]; LL getSum(int a[], int n)
{
LL maxSum = , tmpSum = ;
int maxNum = -;
for (int i = ; i < n; ++i)
{
tmpSum += a[i];
if (maxSum < tmpSum)
maxSum = tmpSum;
else if (tmpSum < )
tmpSum = ;
maxNum = max(maxNum, a[i]);
}
if (maxSum == ) return (LL)maxNum;
return maxSum;
} int main()
{
int nCase;
cin >> nCase;
while (nCase--)
{
int n, P;
cin >> n >> P;
for (int i = ; i < n; ++i)
cin >> a[i];
LL ans = -;
for (int i = ; i < n; ++i)
{
int t = a[i];
a[i] = P;
ans = max(ans, getSum(a, n));
a[i] = t;
}
cout << ans << endl;
}
return ;
}

1002 Senior's Gun

题目链接:1002

题意:有n把枪每把枪都有一定的攻击值,有m个怪兽每个怪兽都有一定的防御值,当攻击值大于防御值时才能击杀怪兽并获得他们差值的酬劳,求最大酬劳。

思路:容易发现最后的方案一定是攻击力最强的k把枪消灭了防御力最弱的k只怪物。

code:

 #include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = ;
typedef long long LL;
int a[MAXN];
int b[MAXN]; bool cmp(int x, int y)
{
return x > y;
} int main()
{
int nCase;
cin >> nCase;
while (nCase--)
{
int n, m;
cin >> n >> m;
for (int i = ; i < n; ++i)
cin >> a[i];
for (int i = ; i < m; ++i)
cin >> b[i];
sort(a, a + n, cmp);
sort(b, b + m);
LL ans = ;
int p = , q = ;
while (p < n && q < m)
{
if (a[p] > b[q])
{
ans += a[p] - b[q];
++p;
++q;
}
else break;
}
cout << ans << endl;
}
return ;
}

BestCoder Round #47的更多相关文章

  1. Bestcoder Round 47 && 48

    1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...

  2. BestCoder Round #47 1003

    solution : 就按题解敲了一遍,好久没写这种dp ;  ;   LL f[MAX][MAX];  ];             scanf(              scanf(,b+); ...

  3. HDU 5281 BestCoder Round #47 1002:Senior's Gun

    Senior's Gun  Accepts: 235  Submissions: 977  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  4. HDU 5280 BestCoder Round #47 1001:Senior's Array

    Senior's Array  Accepts: 199  Submissions: 944  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit ...

  5. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  6. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  7. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  8. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  9. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

随机推荐

  1. CSharp tar类型文件压缩与解压

    最近闲暇时间开始写点通用基础类在写到tar类型文件压缩与解压时遇到点问题 压缩用的类库我是下载的 SharpZipLib_0860版本 先上代码 加压核心 /// <summary> // ...

  2. python-操作exel(xlrd,xlwt)

    1.使用第三方库 python中处理excel表格,常用的库有xlrd(读excel)表.xlwt(写excel)表.openpyxl(可读写excel表)等. xlrd读数据较大的excel表时效率 ...

  3. ebs清除并法管理器所清除的表

    In this Document   Goal   Solution   References Applies to: Oracle Concurrent Processing - Version 1 ...

  4. Cocos2d—X游戏开发之CCTableView详解(十一)

    本来很早就想写关于CCTableView的文章,但是在基本功能实现之后呢,项目需求增加导致对这个控件的研究必须更加深入一点. 好的,现在开始介绍一下这个控件,在Cocos2d—X引擎中,这是一个仿制i ...

  5. Java反射-简单应用

    为了程序更好的维护和扩展,在面向对象思维的世界里,首先是面向接口编程,然后我们应该把做什么和怎么做进行分离. 以下我将用一个开晚会的样例来演示一下,终于达到的效果是:工厂+反射+配置文件实现程序的灵活 ...

  6. css两个紧挨着的css选择器修饰同一个元素

    #status, .commands{ height: 25px; line-height: 25px;}.upload .commands{ float: right;}.hidden{ displ ...

  7. 利用CSS3的transform 3D制作的立方体旋转效果

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. Asp.net 获取图片列表并打包下载

    先引用:ICSharpCode.SharpZipLib.dll 后台代码: using System.IO; using ICSharpCode.SharpZipLib.Zip; using ICSh ...

  9. rac安装中遇到的问题

    ssh 建立面密码登陆时成功,但测试时却不成功,原因在于访问远端的文件时权限不够造成的: grid文件夹:755 grid账户下的.ssh文件夹:700 建立公共ip时需要设定域名:192.168.1 ...

  10. mysql save or update

    原文:http://www.bitscn.com/pdb/mysql/201503/473268.html 背景   在平常的开发中,经常碰到这种更新数据的场景:先判断某一数据在库表中是否存在,存在则 ...