Educational Codeforces Round 61

虽然是场virtual 但这是第一次在cf的比赛里进前100 好开心
【我知道我很菜qvq

比赛链接

cf

A

如果有")("就把它们排在一起放在"(("和“))”中间 然后保证"((","))"一样多就好啦

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
using namespace std;
const int N = 3e5 + 5;
int c1, c2, c3, c4; 
int main(){
    scanf("%d%d%d%d", &c1, &c2, &c3, &c4);
    bool flag = 0;
    if(c1 == c4) flag = 1;
    if(c3 && (!c1)) flag = 0;
    printf("%d", flag);
    return 0;
}

C

有m个区间 从所有区间中删掉两个
求最大覆盖面积
\(n, m <= 5000\)

有一点技巧的暴力?
先暴力处理每个数被覆盖了几次
然后枚举一个区间i 把它的贡献去掉
然后统计现在被覆盖次数为1的前缀和
再枚举一个区间j 用前缀和直接计算最优值
最后恢复区间i的贡献

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
using namespace std;
const int N = 5005;
int n, m;
int cnt[N], one[N], l[N], r[N];
int ans;
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++i){
        scanf("%d%d", &l[i], &r[i]);
        for(int j = l[i]; j <= r[i]; ++j) ++cnt[j];
    }
    for(int i = 1; i <= m; ++i){
        for(int j = l[i]; j <= r[i]; ++j) --cnt[j];
        int res = n;
        for(int j = 1; j <= n; ++j) one[j] = one[j - 1] + (cnt[j] == 1);
        for(int j = 1; j <= m; ++j) if(j != i){
            res = min(res, one[r[j]] - one[l[j] - 1]);
        }
        for(int j = 1; j <= n; ++j) res += (cnt[j] == 0);
        for(int j = l[i]; j <= r[i]; ++j) ++cnt[j];
        ans = max(ans, n - res);
    }
    printf("%d", ans);
    return 0;
}

D

有 n 个笔记本,初始电量 ai,每分钟会耗电 bi,比赛时长k分钟
求最小的充电器的每分钟充电量,使得每个电脑在比赛期间电量非负

二分答案+优先队列

E

这道题题目是Knapsack 然鹅我没有看
一波乱搞 最大取法减6搜索 然后过了?【雾
贴一下正解好了。。
orzFlyppy_White

//乱搞。。

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
using namespace std;
long long W, c[10], ans;
map<long long, long long> mp;
void dfs(long long cur, long long w){
    //if(mp[w] > cur) return; else mp[w] = cur;
    if(!cur){ans = max(ans, W - w); return ;}
    long long d = min(c[cur], w / cur);
    for(long long i = max(0ll, d - 6ll); i <= d; ++i){
        dfs(cur - 1, w - i * cur);
    }
}
int main(){
    scanf("%lld\n", &W);
    for(int i = 1; i <= 8; ++i) scanf("%lld", &c[i]); 
    dfs(8ll, W);
    printf("%lld", ans);
    return 0;
}

F

给定一个长度为n,只含小写字母的串
每次删除一段含有一样字母区间
求最少删多少次删完整个字符串
\(n \leq 500\)

区间dp

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
using namespace std;
const int N = 505;
int n;
char str[N];
int f[N][N];
int main(){
    scanf("%d%s", &n, str + 1);
    for(int i = 1; i <= n; ++i) f[i][i] = 1;
    for(int i = 2; i <= n; ++i){
        for(int l = 1, r = i; r <= n; ++l, ++r){
            if(str[l] == str[r]) f[l][r] = f[l + 1][r - 1] + 1;
            else f[l][r] = min(f[l + 1][r], f[l][r - 1]) + 1;
            for(int k = l; k <= r; ++k){
                f[l][r] = min(f[l][r], f[l][k] + f[k][r] - 1);
            }//这里是把f[l][r] = f[l][k] + f[k + 1][r]和i, j, k三位相同时f[l][r] = str[l][k] + f[k][r] - 1合并了
        }
    }
    printf("%d", f[1][n]);
    return 0;
}

G

本题题解转自The_Virtuoso
题目大意:给定一个序列\(a\),定义它的最长贪心严格上升子序列为\(b\)满足若\(a_{i}\)\(b\)中则\(a_{i}\)之后第一个比它大的也在\(b\)中。给出一个数\(k\),求出所有长度为\(k\)的子区间的最长贪心严格上升子序列。

扫描二维码关注公众号,回复: 6167195 查看本文章

考虑如果选取一个数之后一定会选取它之后第一个比它大的数,那么我们将每个数与它右边第一个比他大的数连边,这样我们就得到了一个森林,再建立一个虚拟节点并将森林中所有根都连向他就得到了一棵树。对于整个序列来说选取了一个点就会选取这个点在树上到根路径上的所有点,而整个序列的答案就是每个点深度的最大值。现在考虑一个子区间的答案,当区间右端点右移时,新加入区间的这个数会对原区间中比这个数小的数的答案\(+1\)也就是将这个数在树上的子树中所有点的答案\(+1\)(这些答案\(+1\)的所有点中虽然包括区间之前的数但显然这些数的答案不会比区间内数的答案更大,最多只会与最大值相同),同样当区间左端点右移时,就将这个数在树上的子树中所有点的答案\(-1\)来确保区间之前的数的答案不会比区间中数的答案更优。我们对整棵树的\(dfs\)序维护线段树,每次询问只需要分别将左右端点右移然后在线段树上区间修改并查询全局最大值即可。至于每个数右边第一个大于它的数只需要维护一个单调递减的单调栈然后每次弹栈时将栈顶与当前数连边即可。

猜你喜欢

转载自www.cnblogs.com/hjmmm/p/10831604.html
今日推荐