Codeforces Round #FF (Div. 2)
又一场中国场,果然注定被虐的场。。。
A,B:都很水,差不多模拟就好了;
C题:CF难得的题意简洁,
我们可以预处理出从左到右递增的数列个数,
举个例子:1 3 2 4 5 7
L[I] 从左开始 1 2 1 2 3 4
从右往左是递减的个数: R[I] 2 1 1 3 2 1
我们发现对于i: A[I-1]<A[I+1]-1 才有可能改变A[I]找到更多的数,
ANS=MAX(ANS,MAX(L[I-1],R[I+1])+1);
具体有很多被HACK的细节,耐心处理下
代码:
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#define N 111111
using namespace std; int a[N],l[N],r[N];
int main()
{
int n;
cin>>n;
for (int i=;i<=n;i++){
cin>>a[i];
l[i]=r[i]=;
}
int ans=;
for (int i=;i<=n;i++)
{
if (a[i]>a[i-]) l[i]+=l[i-];
ans=max(ans,l[i]);
} for (int i=n-;i>=;i--)
if (a[i]<a[i+]) r[i]+=r[i+]; l[]=-;
r[n+]=-;
a[]=;
a[n+]=-;
for(int i=;i<=n;i++)
{
if (a[i-]<a[i+]-) ans=max(ans,l[i-]+r[i+]+);
else ans=max(ans,max(r[i+],l[i-])+);
} cout<<ans<<endl;
return ;
}
补充D题:
我们预先统计每行,每列的和,
假如,我们选出了X行(K-X)列,那么ANS还需要减去X*(K-X)*P,好好体会这个方程式。。
然后构造优先堆,每次去最大,求出行拿1-K次,列拿1-K次,
其实代码可以看到思路
CODE:
#include<stdio.h>
#include<queue>
#include<math.h>
#include<string.h>
using namespace std;
typedef long long ll;
priority_queue<ll> Q;
ll r[],c[],f[],g[];
int n,m,k,p;
int main()
{
scanf("%d%d%d%d",&n,&m,&k,&p);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
{
int z;
scanf("%d",&z);
r[j]+=z;
c[i]+=z;
} while (!Q.empty()) Q.pop();
for (int i=;i<=n;i++) Q.push(c[i]);
for (int i=;i<=k;i++)
{
int t=Q.top();
Q.pop();
f[i]=f[i-]+t;
Q.push(t-m*p);
} while (!Q.empty()) Q.pop();
for (int i=;i<=m;i++) Q.push(r[i]);
for (int i=;i<=k;i++)
{
int t=Q.top();
Q.pop();
g[i]=g[i-]+t;
Q.push(t-n*p);
} ll ans=-123456789101112334ll;
for (int i=;i<=k;i++)
ans=max(ans,f[i]+g[k-i]-(ll) p*(ll)i*(ll)(k-i));
printf("%I64d\n",ans);
return ;
}
Codeforces Round #FF (Div. 2)的更多相关文章
- DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...
- Codeforces Round #FF (Div. 2)__E. DZY Loves Fibonacci Numbers (CF447) 线段树
http://codeforces.com/contest/447/problem/E 题意: 给定一个数组, m次操作, 1 l r 表示区间修改, 每次 a[i] + Fibonacci[i-l ...
- Codeforces Round #FF (Div. 2) 题解
比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit p ...
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列
B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we kn ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划
A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列
链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行 ...
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
解题报告:输入一个数列,选取一个子数列,要求最多只能改动这个子数列中的一个数,使得这个子数列是严格的升序的(严格升序没有相等的) 我的做法是,第一步把这个 数列的每个升序的子数列都找出来,然后看这些子 ...
- Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash
A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...
随机推荐
- nandflash操作详解
1.nandflash就是嵌入式系统的硬盘 2.分类(1)MLC:存储单元格存储两位,慢,偏移,寿命短,容量大(2)SLC:存储一位.快,寿命长,容量小,昂贵 3访问:(1)独立编址,有专用的控制器, ...
- .NET设计模式系列文章 from TerryLee
http://www.cnblogs.com/Terrylee/archive/2006/07/17/334911.html 最初写探索设计模式系列的时候,我只是想把它作为自己学习设计模式的读书笔记来 ...
- DoubanFm之设计模式(一)
前两版DoubanFm写的太戳,第一版可以忽略,当是熟悉WP手机的一些API.. 第二版用了比较多的依赖注入,熟悉了Messenger,过后越写越大,感觉不对,赶快打住..现在开始好好思考各模块了. ...
- 刀哥多线程笔记之gcd-02-block
block 概念 block 是 C 语言的 是一种数据类型,可以当作参数传递 是一组预先准备好的代码,在需要的时候执行 动画 block 回顾 self.demoView.center = CGPo ...
- C#巧用Excel模版变成把Table打印出来
将一个做好的Excel模版,通过程序填上数据然后打印出来这个需求有两种方法一种是通过代码打开Excel模版然后填入数据然后再打印. 第二种方法就是我将要介绍的 1.将Excel设置好格式另存为HTML ...
- Linux编译内核提示'make menuconfig' requires the ncurses libraries错误
原来使用的ubuntu 11.10系统由于误操作,导致系统崩溃,重新安装了ubuntu 11.10: 在编译内核的时候,提示如下错误: dingq@wd-u1110:~/hwsvn/2sw/1prj_ ...
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
- 浅谈.NET中闭包
什么是闭包 闭包可以从而三个维度来说明.在编程语言领域,闭包是指由函数以及与函数相关的上下文环境组合而成的实体.通过闭包,函数与其上下文变量之间建立起关联关系,上下文变量的状态可以在函数的多次调用过程 ...
- WCF note1
Summary of WCF Client to use service use ChannelFactory to create proxy to use service. Client code ...
- 微软职位内部推荐-Software Engineer II-Office Incubation
微软近期Open的职位: Office China team is looking for experienced engineers to improve consumer experience i ...