设为首页 加入收藏

TOP

cf1060E. Sergey and Subway(思维 枚举)
2018-12-06 22:08:48 】 浏览:13
Tags:cf1060E. Sergey and Subway 思维 枚举

题意

题目链接

Sol

好好读题 => 送分题

不好好读题 => 送命题

开始想了\(30\)min数据结构发现根本不会做,重新读了一遍题发现是个傻逼题。。。

\(C_{i, j} = a[i] * b[j]\)

根据乘法分配律,题目就变成了在数组\(a, b\)中分别选一段连续的区间,要求权值和相乘\(<= X\),最大化区间长度乘积

\(n^2\)模拟一下即可

#include<bits/stdc++.h> 
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long 
#define LL long long 
#define rg register 
#define pt(x) printf("%d ", x);
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
#define chmin(x, y) (x = x < y ? x : y)
using namespace std;
const int MAXN = 2001, INF = 1e18 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

int N, M, a[MAXN], b[MAXN], f[MAXN], g[MAXN], Lim, ans;
main() {
    N = read(); M = read();
    for(int i = 1; i <= N; i++) a[i] = read();
    for(int i = 1; i <= M; i++) b[i] = read();
    memset(f, 0x7f, sizeof(f));
    memset(g, 0x7f, sizeof(g));
    Lim = read();
    for(int i = 1; i <= N; i++) {
        int mn = 0;
        for(int j = i; j <= N; j++) mn += a[j], chmin(f[j - i + 1], mn);
    }
    for(int i = 1; i <= M; i++) {
        int mn = 0;
        for(int j = i; j <= M; j++) mn += b[j], chmin(g[j - i + 1], mn);
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= M; j++) {
            if(f[i] * g[j] <= Lim)
                ans = max(ans, j * i);
        }
    }
    cout << ans;
    return 0;   
}

编程开发网
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇浅析libuv源码-获取精确时间 下一篇BZOJ1927: [Sdoi2010]星际竞速(最..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

array(4) { ["type"]=> int(8) ["message"]=> string(24) "Undefined variable: jobs" ["file"]=> string(32) "/mnt/wp/cppentry/do/bencandy.php" ["line"]=> int(214) }