codeforces 1060 C
https://codeforces.com/contest/1060/problem/C
题意:给你一个长度为n的数列a和长度为m的数列b,定义c(i,j)=ai*bj,得到c矩阵,给定值x,求c矩阵中的子矩阵和小于等于x的最大的元素个数
题解:和hihocoder上面一题很想~链接http://hihocoder.com/problemset/problem/1502 ,不同的是这题用n^3的做法会T哭
我们可以想到,一个子矩阵的和就是 (a[i]+a[i+1]+...+a[j])*(b[i]+b[i+1]+...+b[j])。于是我们先预处理a和b 的前缀和,然后n^2判断即可
代码如下:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 1e5+;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
double dpow(double a,LL b){double ans=1.0;while(b){if(b%)ans=ans*a;a=a*a;b/=;}return ans;}
LL a[],b[],c[][];
LL sum[][];
LL suma[];
LL sumb[];
int main(){
#ifndef ONLINE_JUDGE
FIN
#endif
LL n,m,x;
cin>>n>>m;
a[]=b[]=;
for(int i=;i<=n;i++){
cin>>a[i];
a[i]=a[i]+a[i-];
}
for(int i=;i<=m;i++){
cin>>b[i];
b[i]=b[i]+b[i-];
}
cin>>x;
memset(suma,INF,sizeof(suma));
memset(sumb,INF,sizeof(sumb));
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(j+i->n) break;
suma[i]=min(suma[i],a[j+i-]-a[j-]);
}
}
for(int i=;i<=m;i++){
for(int j=;j<=m;j++){
if(j+i->m) break;
sumb[i]=min(sumb[i],b[j+i-]-b[j-]);
}
}
LL ans=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if((LL)suma[i]*sumb[j]<=x){
ans=max(ans,i*j*1LL);
}
}
} cout<<ans<<endl;
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++){
// cout<<c[i][j]<<" ";
// }
// cout<<endl;
// }
}
codeforces 1060 C的更多相关文章
- codeforces 1060 D
https://codeforces.com/contest/1060/problem/D 题意:你可以用1个及以上的圆桌,给n个人排座位,每个人左边需要有Li个空凳子,右边需要有Ri个空凳子,问你最 ...
- codeforces 1060 B
https://codeforces.com/contest/1060/problem/B 题意:给你一个数C ,你要找到两个数A.B,使得A+B=C并且A的每个位的数的和最大,求最大的和是多少 题解 ...
- codeforces 1060 A
https://codeforces.com/contest/1060/problem/A 题意:电话号码是以8开头的11位数,给你n 个数问最多可以有多少个电话号码 题解:min(8的个数,n/11 ...
- CodeForces 1060 B Maximum Sum of Digits
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...
- Codeforces 1060 F. Shrinking Tree
题目链接 一道思维好题啊...感觉这种类型的题很检验基本功是否扎实(像我这样的就挂了). 题意:你有一棵\(n\)个点的树,每次随机选择一条边,将这条边的两个端点合并,并随机继承两个点标号中的一个,问 ...
- CodeForces Round #550 Div.3
http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...
- Codeforces 1060E(思维+贡献法)
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...
- Codeforces Round #513 by Barcelona Bootcamp C. Maximum Subrectangle(双指针+思维)
https://codeforces.com/contest/1060/problem/C 题意 给两个数组,a数组有n个元素,b数组有m个元素,两个数组元素互相相乘形成n*m的矩阵,找一个子矩阵,元 ...
- Codeforces Round #513-ABCD
ABC现场做出,涨了八十几分吧.D有点思路不知道怎么实现,赛后看题解发现巨简单,想得太复杂了.蓝瘦. A----http://codeforces.com/contest/1060/problem/A ...
随机推荐
- grunt in webstorm
1.install grunt sudo npm install -g grunt-cli npm install grunt --save-dev
- P1332 血色先锋队
P1332 血色先锋队 题目描述 巫妖王的天灾军团终于卷土重来,血色十字军组织了一支先锋军前往诺森德大陆对抗天灾军团,以及一切沾有亡灵气息的生物.孤立于联盟和部落的血色先锋军很快就遭到了天灾军团的重重 ...
- Python未彻底测试的项目
第一 socket 第二 twisted 第三 tornado 第四 微信网页版本登录 第五:进程,线程,协程间关系 第六:TCP三次握手 第七:堡垒机 第八:重写django admin
- 创龙DSP6748开发板SYS/BIOS的LED闪烁-第2篇
1. 作为1个456MHz的处理器,不跑个操作系统说不过去,直接打开工程\Demo\SYSBIOS\Application\GPIO_LED,主函数比较简单 // 创建任务 Task_create(t ...
- 根据STATUS信息对MySQL进行优化
mysql> show global status;可以列出MySQL服务器运行各种状态值,我个人较喜欢的用法是show status like '查询值%';一.慢查询mysql> sh ...
- Scala学习笔记(二):运行脚本文件
在某个目录(如:F:\)下新建一个文本文件,命名为:hello.scala 其内容为: println("Hello World!") 那么这个时候该怎么运行这个脚本文件呢? 通过 ...
- js滚动及可视区域的相关的操作
element.getBoundingClientRect 判断指定元素相对于页面可视窗口的位置信息,通常结合windows.onScroll方法使用,当element.getBoundingClie ...
- ES5新增数组方法(4):every
检查数组元素的每个元素是否符合条件. // 数组中的元素全部满足指定条件返回true let arr = [1, 3, 5, 7, 9]; console.log(arr.every((value, ...
- Python3 使用 logging.basicConfig() 配置输出日志中的中文乱码解决办法
在源码中修改encoding='utf-8',因为 logging.basicConfig() 配置时实际上是用到了4大组件,只不过给了默认值而已,如果不知道怎么找到源码,告诉你们个快捷键,选中你lo ...
- 分布式一致性算法之Paxos原理剖析
概述 Zookeeper集群中,只有一个节点是leader节点,其它节点都是follower节点(实际上还有observer节点,不参与选举投票,在这里我们先忽略,下同).所有更新操作,必须经过lea ...