Codeforces Round #642 (Div. 3)

Posted lukelmouse

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #642 (Div. 3)相关的知识,希望对你有一定的参考价值。

VP

A 题分析的太慢了

B 题数据范围很小,却一直xjb乱想其他的东西,直接暴力就过了,想太多了

C 题太脑残了,已经推出来公式,看了半天想不通为什么错,原来是 f[k] = f[k - 2] + (k - 1ULL) * 4 * (k / 2) 加法的时候爆ULL了

D 题写了个DFS,顺序没写对,WA 1,赛后发现这题跟DFS有个P的关系

D

记得重载 (<) 的时候,里面写的全是反的!

priority_queue 可以省略剩下两个变量,只用写第一个类型就 ok 了

vector 开在函数里面会爆的,(2e5) 还是全局变量保险!

这题模拟的时候,可以感觉到一种优先队列的思想要自己提炼出来

#include <bits/stdc++.h>
using namespace std;
#define endl ‘
‘ 
#define IO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef pair<int,int> PII;

const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const db EXP = 1e-9;
struct node {
	int l, r, len;
    bool operator < (const node & T) const {
        if(T.len != len) return len < T.len;
        return l > T.l;
    }
};
int a[N];
int main() {
#ifndef ONLINE_JUDGE
    freopen("D:/scode/in.txt","r",stdin);
    //freopen("D:/scode/out.txt","w",stdout);
#endif
    IO;
    int t;
    cin >> t;
    while(t --) {
        int n;
        cin >> n;
        priority_queue<node> q;
        q.push({1,n,n});
        for(int i = 1;i <= n; ++i) {
            node t = q.top();
            q.pop();
            int num = (t.len % 2) ? (t.l + t.r) / 2 : (t.l + t.r - 1) / 2;
            a[num] = i;
            q.push({t.l,num - 1,num - t.l});
            q.push({num + 1,t.r,t.r - num});
        }
        for(int i = 1;i <= n; ++i) cout << a[i] << ‘ ‘;
        cout << endl;
    }
    return 0;
}

参考

streamazure

E

这题不看别人题解,根本没想到DP啊,还以为贪心呢

看来有时候要多往DP方面想想了,这方面太弱了

#include <bits/stdc++.h>
using namespace std;
#define endl ‘
‘ 
#define IO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef pair<int,int> PII;

const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const db EXP = 1e-9;
int f[N][2],pre[N],n,k;
char s[N];
int main() {
#ifndef ONLINE_JUDGE
    freopen("D:/scode/in.txt","r",stdin);
    //freopen("D:/scode/out.txt","w",stdout);
#endif
    IO;
    int t;
    cin >> t;
    while(t --) {
        cin >> n >> k;
        for(int i = 0;i <= n; ++i) f[i][0] = f[i][1] = INF;
        cin >> s + 1;
        for(int i = 1;i <= n; ++i) pre[i] = pre[i - 1] + (s[i] - ‘0‘);
        f[0][0] = f[0][1] = 0;
        for(int i = 1;i <= n; ++i) {
            f[i][0] = min(f[i - 1][0],f[i - 1][1]) + (s[i] == ‘1‘);
            f[i][1] = min(pre[i - 1],f[max(0,i - k)][1] + pre[i - 1] - pre[max(0,i - k)]) + (s[i] == ‘0‘);
        }
        cout << min(f[n][0],f[n][1]) << endl;
    }
    return 0;
}

参考

AKone123456

以上是关于Codeforces Round #642 (Div. 3)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #642 (Div. 3)

Codeforces Round #642 (Div. 3)

Codeforces Round #642 (Div. 3)

Codeforces Round #642 (Div. 3) 题解

Codeforces Round #642 (Div. 3)A~D

Codeforces Round #642 (Div. 3)A~D