2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

https://codeforc.es/gym/101982/

A - Exam

2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)_第1张图片

很显然,要把大家做一样的优先认为大家都是对的,大家做不一样的认为自己是对的。最后假如对方有剩余的题是对的那么就要从中减去。

#include
using namespace std;

int k;
char s[1005];
char t[1005];

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    scanf("%d%s%s", &k, s + 1, t + 1);
    int n = strlen(s + 1);
    int cnt = 0;
    for(int i = 1; i <= n; ++i) {
        if((s[i] == t[i])) {
            if(k) {
                ++cnt;
                --k;
            }
        } else {
            ++cnt;
        }
    }
    printf("%d\n", cnt - k);
}

B - Coprime Integers

2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)_第2张图片

求范围内的互质数对,莫比乌斯反演的逗比模板题。而且还是线性筛就够了。小心溢出。

#include
using namespace std;
typedef long long ll;

int n;
const int MAXN = 1e7;

int sumu[MAXN + 5];
int pri[MAXN + 5], pritop;
bool notpri[MAXN + 5];

void sieve(int n) {
    notpri[1] = sumu[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!notpri[i])
            pri[++pritop] = i, sumu[i] = -1;
        for(int j = 1; j <= pritop && i * pri[j] <= n; j++) {
            notpri[i * pri[j]] = 1;
            if(i % pri[j])
                sumu[i * pri[j]] = -sumu[i];
            else {
                sumu[i * pri[j]] = 0;
                break;
            }
        }
    }
    for(int i = 2; i <= n; i++)
        sumu[i] += sumu[i - 1];
}

ll Sum(int n, int m) {
    ll res = 0;
    int N = min(n, m);
    for(int l = 1, r; l <= N; l = r + 1) {
        r = min(n / (n / l), m / (m / l));
        res += 1ll * (sumu[r] - sumu[l - 1]) * (n / l) * (m / l);
    }
    return res;
}

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    sieve(MAXN);
    int a, b, c, d;
    while(~scanf("%d%d%d%d", &a, &b, &c, &d)) {
        printf("%lld\n", Sum(b, d) - Sum(b, c - 1) - Sum(a - 1, d) + Sum(a - 1, c - 1));
    }
}

C - Contest Setting

2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)_第3张图片

这个逗比题怎么弄这么久。要求不可重,恰好k种,去重之后n²dp就可以了。

#include
using namespace std;
typedef long long ll;

const int MOD=998244353;

int a[1005];
int cnt[1005];
int dp[1005][1005];

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        cnt[a[i]]++;
    }
    sort(a+1,a+1+n);
    int t=unique(a+1,a+1+n)-(a+1);
    dp[0][0]=1;
    for(int i=1;i<=t;++i){
        dp[i][0]=1;
        for(int j=1;j<=min(i,k);++j)
            dp[i][j]=(1ll*dp[i-1][j-1]*cnt[a[i]]%MOD+dp[i-1][j])%MOD;
    }
    printf("%d\n",dp[t][k]);
}

L -Liars

2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)_第4张图片

应该是从大到小暴力枚举。

#include
using namespace std;
typedef long long ll;

int a[1005];
int b[1005];

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    int n, ans = -1;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d%d", &a[i], &b[i]);
    }
    for(int i = n; i >= 0; --i) {
        int cnt = 0;
        for(int j = 1; j <= n; ++j) {
            if(a[j] <= i && i <= b[j])
                ++cnt;
        }
        if(cnt == i) {
            ans = cnt;
            break;
        }
    }
    printf("%d\n", ans);
}

J - Time Limits

2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)_第5张图片

#include
using namespace std;
typedef long long ll;

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    int n, s;
    scanf("%d%d", &n, &s);
    int maxtime = 0;
    for(int i = 1; i <= n; ++i) {
        int t;
        scanf("%d", &t);
        maxtime = max(maxtime, t);
    }

    printf("%d\n", ((maxtime * s) + 999) / 1000);
}

转载于:https://www.cnblogs.com/Inko/p/11437717.html

你可能感兴趣的:(2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1))