ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

2020 年百度之星·程序设计大赛 - 复赛

2020-08-10 11:02:26  阅读:686  来源: 互联网

标签:typedef int ll 2020 pair define 之星 复赛 mod


C是真的不会, 连续区间第k大

A

取好模数就行

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;

const int N = 1e5 + 5, mod = 998244353;

ll n, m, _, k;
ll a, b;

int qpow(int a, int b) {
    int ans = 1;
    for (; b; b >>= 1, a = (ll)a * a % mod)
        if (b & 1) ans = (ll)ans * a % mod;
    return ans;
}

int main() {
    IO;
    int c100 = qpow(100, mod - 2);
    for (cin >> _; _; --_) {
        cin >> n >> a >> b;
        int c = __gcd(a, (ll)100);
        a = a / c * qpow(100 / c, mod - 2) % mod;
        c = __gcd(b, (ll)100);
        b = b / c * qpow(100 / c, mod - 2) % mod;
        c = __gcd(n, a);
        ll d = (n / c * qpow(a / c, mod - 2) - 1) % mod;
        m = ((n - d * b) % mod + mod) % mod;
        cout << m << '\n';
    }
    return 0;
}

B

暴力

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;

const int N = 1e5 + 5;

int n, m, _, k;
char s[N], t[N];
int w, x, y, z;
int res[N];

void work(int k, int a) {
    res[k] = w + x + 1 + x + z;
    if (!a) {
        int c = 1e9, d = 0;
        rep(i, k + 1, n) {
            if (s[i] == t[i]) ++d;
            else --d;

            if (s[i] != '1') break;
            else {
                if (t[i] == '1') c = min(d, c);
                else c = min(d + 2, c);
            }
            if (i == n) ++d;
        }
        if (k == n) ++d;
        res[k] += min(d, c);
    }
}

int main() {
    IO;
    for (cin >> _; _; --_) {
        cin >> n >> s + 1 >> t + 1;
        w = x = y = z = 0;
        rep(i, 1, n) {
            if (t[i] != s[i]) work(i, t[i] - '0');
            else res[i] = 2e5;

            w += (t[i] == '0') && (s[i] == '0');
            x += (t[i] == '1') && (s[i] == '0');
            y += (t[i] == '0') && (s[i] == '1');
            z += (t[i] == '1') && (s[i] == '1');
        }

        m = x + y, w = 0;
        per(i, n, 1) {
            m = min(m, res[i] + w);
            w += (s[i] != t[i]);
        }
        cout << m << '\n';
    }
    return 0;
}

标签:typedef,int,ll,2020,pair,define,之星,复赛,mod
来源: https://www.cnblogs.com/2aptx4869/p/13468530.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有