其他分享
首页 > 其他分享> > Educational Codeforces Round 88 (Rated for Div. 2) 现ABCE 补D 欠F

Educational Codeforces Round 88 (Rated for Div. 2) 现ABCE 补D 欠F

作者:互联网

[CodeForces 1359A] Berland Poker 小学生都会的贪心:

一个人尽可能多拿拿到x,剩下的均分上取整为y,输出x-y

 

[CodeForces 1359B] New Theatre Square 还是小学生都会的贪心:

如果两个格子一起的钱比一个格子的钱的两倍还大就全部一个格子一个格子地铺,不然能铺两个格子就铺两个格子。

 

[CodeForces 1359C] Mixing Water 简单计算:

需求的水温等于h时候,1回合即可;需求水温小于等于(h+c)/2时候,2回合;其他利用公式h*(n+1)+c*n=t*(2n+1),求出n判断n上取整和下取整情况下哪个离需求水温最近就是哪个(一样近就是下取整),然后输出是2*(n的上取整或下取整)+1。

 

[CodeForces 1359D] Yet Another Yet Another Task DP好题:

如果是单纯的求一段连续片段上的最大和就很简单,如下:

int res = 0, sum = 0;
for(int i = 0; i < n; i++){
    sum += a[i];
    sum = max(0, sum);
    res = max(res, sum);
}

这道题多了一个条件,需要去掉连续段上那个最大的值。注意到 ai 的大小不超过30,那么可以想到枚举连续段上的元素大小上限,超过上限的部分就断开不取,然后维护答案的时候记得剪掉一个区间最大值。其他步骤和经典的问题一样,详见代码。

const int maxn = 1e5 + 5;
int a[maxn];

int main(){
    int n = read();
    for(int i = 0; i < n; i++) a[i] = read();
    int res = 0;
    for(int i = 1; i <= 30; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum += a[j];
            if(a[j] > i) sum = 0;
            sum = max(sum, 0);
            res = max(res, sum - i);
        }
    }
    cout << res << endl;
    return 0;
}
View Code

 

[CodeForces 1359E] Modular Stability 基础数论(较水):

容易发现取模的顺序改变而结果不变一定是所有的模数都是最小模数的倍数,然后从小到大枚举最小模数,求个组合数累加到结果上就行了。

const int Mod = 998244353;

const int maxn = 5e5 + 5;
LL fac[maxn];

void init(int Mod){
    fac[0] = 1;
    for(int i = 1; i < maxn; i++)
        fac[i] = fac[i - 1] * i % Mod;
}

int extgcd(int a, int b, int &x, int &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int mod_inverse(int a, int mod){
    int x, y;
    extgcd(a, mod, x, y);
    return (mod + x % mod) % mod;
}

int C(LL n, LL m, int Mod){
    if(m - n < n) n = m - n;
    LL res = 1;
    for(int i = 0; i < n; i++){
        res = (res * m) % Mod;
        m--;
    }
    int tmp = fac[n];
    res = (res * mod_inverse(tmp, Mod)) % Mod;
    return res;
}

int main(){
    init(Mod);
    int n = read(), k = read(), res = 0;
    if(n < k) {cout << 0 << endl; return 0;}
    k--;
    for(int i = 1; ; i++){
        int tmp = n / i - 1;
        if(tmp < k) break;
        res = (res + C(k, tmp, Mod)) % Mod;
    }
    cout << res << endl;
    return 0;
}
View Code

 

[CodeForces 1359F] RC Kaboom Show 二分+计算几何:

其实是很难的,并不会做,但是有人用枚举卡常数过了,贴个卡常数的代码吧。

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 26000;
int xx[MAXN];
int yy[MAXN];
int dx[MAXN];
int dy[MAXN];
int ss[MAXN];
double norm_d[MAXN];
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
 
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> xx[i] >> yy[i] >> dx[i] >> dy[i] >> ss[i];
        int g = __gcd(dx[i], dy[i]);
        g = llabs(g);
        dx[i] /= g;
        dy[i] /= g;
        norm_d[i] = sqrt(dx[i]*dx[i] + dy[i]*dy[i]);
    }
 
    double res = 1e18;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            int x = xx[i] - xx[j], y = yy[i] - yy[j];
            int det = dx[i]*dy[j] - dx[j]*dy[i];
            if (det == 0) {
                int lambda = x / dx[i];
                if (x != lambda * dx[i] or y != lambda * dy[i]) continue;
                int v = 0;
                if ((x > 0) != (dx[i] > 0)) v += ss[i];
                if ((x > 0) == (dx[j] > 0)) v += ss[j];
                if (v == 0) continue;
                if (lambda < 0) lambda = -lambda;
                res = min(res, (lambda * norm_d[i])/v);
            } else {
                int a = - x * dy[j] + y * dx[j];
                int b = dx[i] * y - dy[i] * x;
                if (a != 0 and (a > 0) != (det > 0)) continue;
                if (b != 0 and (b > 0) != (det > 0)) continue;
                double ris = max((a*norm_d[i]) / (ss[i]*det), (b*norm_d[j]) / (ss[j]*det));
                res = min(res, ris);
            }
        }
    }
    cout.precision(10);
    if (res > 1e17) cout << "No show :(\n";
    else cout << fixed << res << "\n";
}
View Code

 

标签:ABCE,Educational,Rated,int,res,sum,dx,dy,Mod
来源: https://www.cnblogs.com/ACHappy-yjy/p/12992004.html