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. 关于javascript跨域及JSONP的原理与应用

    同源策略,它是由Netscape提出的一个著名的安全策略,现在所有的可支持javascript的浏览器都会使用这个策略. 为什么需要同源策略,这里举个例子: 假 设现在没有同源策略,会发生什么事情呢? ...

  2. dllimport与dllexport作用与区别

    我相信写WIN32程序的人,做过DLL,都会很清楚__declspec(dllexport)的作用,它就是为了省掉在DEF文件中手工定义导出哪些函数的一个方法.当然,如果你的DLL里全是C++的类的话 ...

  3. poj2871

    #include <stdio.h> #include <stdlib.h> //法一 int main() { ]; ,tmp; ) { scanf("%lf&qu ...

  4. 链表-Partition List

    struct ListNode* partition(struct ListNode* head, int x) { struct ListNode *p1=(struct ListNode*)mal ...

  5. Ignatius and the Princess III(母函数)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  6. at org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)异常解决

    部署项目,启动tomcat一切正常.输入项目地址后 tomcat报例如以下错误: java.lang.NullPointerException at org.apache.jsp.index_jsp. ...

  7. Android 自动编译、打包生成apk文件 3 - 使用SDK Ant方式

      相关文章列表: < Android 自动编译.打包生成apk文件 1 - 命令行方式> < Android 自动编译.打包生成apk文件 2 - 使用原生Ant方式> &l ...

  8. 什么时候css会见less

    在一定程度上,css不能被视为一个节目.虽然和其他语言,它有自己的规范.编码,但它的笨拙实在让我失望. 不喜欢css是由于不管怎么优化代码.项目大到一定程序后.都会看上去一团乱.并且有时候一个bug的 ...

  9. 浅谈HtmlParser

    使用Heritrix抓取到自己所需的网页后,还需要对网页中的内容进行分类等操作,这个时候就需要用到htmlparser,但是使用htmlparser并不是那么容易!因为相关的文档比较少,很多更能需要开 ...

  10. 数据持久化------Archiving(归档,解档)

    其中TRPerson为自定义的继承自NSObject的类的子类  其中有两个属性,name 和 age .h文件 #import @interface TRPerson : NSObject<& ...