洛谷11月月赛题解(A-C)

心路历程

辣鸡T3卡我1.5h题意,要不是最后nlh跟我解释了一下大样例估计这次是真凉透了。。

A P4994 终于结束的起点

打出暴力来发现跑的过最大数据??

保险起见还是去oeis了一波,然后被告知第一个满足条件的位置不会超过(2n +2)

赢了

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP make_pair 
#define fi first
#define se second 
using namespace std;
const int MAXN = 1e7 + 10;
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 f[MAXN] = {0, 1};
int main() {
    int M = read();
    for(int i = 2; i; i++) {
        f[i] = (f[i - 1] + f[i - 2]) % M;
        if(f[i - 1] == 0 && f[i] == 1) {printf("%d
", i - 1); break;}
    }
    return 0;
}

B P4995 跳跳!

为啥(n leqslant 300)啊。。出题人这么放烟雾弹真的好么。。。

直接排序之后每次在没跳过的最大的和没跳过的最小的之间跳

开始的时候跳的最大的

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP make_pair 
#define fi first
#define se second 
#define LL long long 
using namespace std;
const int MAXN = 1e6 + 10;
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; 
LL a[MAXN];
int main() {
    N = read();
    for(int i = 1; i <= N; i++) a[i] = read();
    sort(a + 1, a + N + 1, greater<int>());
    LL ans = a[1] * a[1], l = 1, r = N, opt = 0;
    for(int i = 1; i <= N - 1; i++, opt ^= 1) {
        ans += abs((a[l] - a[r]) * (a[l] - a[r]));
        if(!opt) l++;
        else r--;
    }
    cout << ans;
    return 0;
}

B P4996 咕咕咕

看不懂题其实也不能完全怪出题人吧。。还是自己太菜了。。

直接爆搜+记忆化就能骗到(40)分(莫名奇妙wa掉两个点)

交上去的时候已经(11:47)了。。吃饭的时候发现可以把(1)的个数相同的数一起算,他们的系数都是一样的。

然后就做完了。。

时间复杂度:(O(2^n))

好像可以直接用组合数算系数?

#include<cstdio>
#include<map>
#include<iostream>
#define Pair pair<int, int>
#define MP make_pair 
#define fi first
#define se second 
#define LL long long  
using namespace std;
const int MAXN = 3e6 + 10, mod = 998244353;
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, Lim, ans, ou[MAXN], in[MAXN];
int mp[1 << 22];
void add(int &x, int y) {
    if(x + y < 0) x = x + y;
    else x = (x + y >= mod ? x + y - mod : x + y);
}
int mul(int x, int y) {
    return 1ll * x * y % mod;
}
int trans(string x) {
    int ou = 0;
    for(int k = 0; k < N; k++) if(x[k] == '1') ou |= 1 << k;
    return ou;
}
int g(int x) {
    return __builtin_popcount(x);
}
int dfs(int sta) {
    if(ou[g(sta)]) return ou[g(sta)];
    for(int i = sta + 1; i <= Lim; i++) 
        if((i & sta) == sta) add(ou[g(sta)], dfs(i));
    return ou[g(sta)];
}
int dfs2(int sta) {
    if(in[g(sta)]) return in[g(sta)];
    for(int i = 0; i < sta; i++) 
        if((i & sta) == i) add(in[g(sta)], dfs2(i));
    return in[g(sta)];
}
int main() {
    N = read(); M = read(); Lim = (1 << N) - 1;
    for(int i = 1; i <= M; i++) {
        string s; int val;
        cin >> s; val = read() % mod; 
        mp[trans(s)] = val;
    }
    in[0] = 1; ou[g(Lim)] = 1;
    dfs(0); dfs2(Lim); 
    for(int i = 0; i <= Lim; i++) add(ans, mul(mp[i], mul(ou[g(i)], in[g(i)])));
    cout << ans;
}

D

没时间写暴力了。

puts("-1 -1")骗了10分。。

原文地址:https://www.cnblogs.com/zwfymqz/p/9904045.html