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 ...
随机推荐
- Oracle Study Note : Users and Basic Security
1. view the default user account SQL> select username from dba_users; 2. lock all users and set t ...
- C# WinForm自定义控件响应键盘事件
自己定义的winform控件,用其他键盘事件都无法响应,只有用ProcessCmdKey事件可以达到目的(别忘了主窗体的KeyPreview属性要设置为true),写法如下: prot ...
- db2建立表空间
--缓冲池 CREATE BUFFERPOOL EMP_BUF_POOL IMMEDIATE ALL DBPARTITIONNUMS SIZE 250 NUMBLOCKPAGES 0 PAG ...
- hdu 5349 MZL's simple problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5349 MZL's simple problem Description A simple proble ...
- poj 1459 Power Network
题目连接 http://poj.org/problem?id=1459 Power Network Description A power network consists of nodes (pow ...
- HMMPfam的安装使用手记(转载)
转载至:http://blog.sina.com.cn/s/blog_3f6403290100rb61.html(感谢原文作者) HMMPfam的安装使用手记前言 简要介绍一下 HMMPfam吧.这还 ...
- 58.xilinx原语DCM,PLL的使用
DCM_BASE 基本数字时钟管理模块的缩写,是相伴和频率可配置的数字锁相环电路,常用于FPGA系统中复杂的时钟管理.如需要频率和相位动态配置,则可以选用DCM_ADV原语,如需要相位动态偏移,可使用 ...
- 按键精灵实现自动退出的MsgBox消息框
要实现自动倒计时退出的消息框,代码如下: Set wsh = CreateObject("WScript.Shell") wsh.popup "设置完毕,3秒后自动退出! ...
- NSString+NSStringForJava.m
// // NSString+NSStringForJava.m // NSStringCategory // // Created by Ryan Tang on 12-10-17. // Copy ...
- ostream类重载的operator<<()函数
ostream类重载了operator<<()以识别不同的类型,如: int short long unsigned int unsigned short unsigned long f ...