头像

hairrrrr




离线:1小时前


活动打卡代码 AcWing 680. 剪绳子

hairrrrr
5小时前
#include<cstdio>

#define N 100010

int n, m;
int Rope[N];

bool check(double mid)
{
    int cnt = 0;
    for(int i = 0; i < n; ++i)
    {
        cnt += Rope[i] / mid;
        if(cnt >= m) return true;
    }
    return false;
}

int main(void)
{
    scanf("%d%d", &n, &m);

    for(int i = 0; i < n; ++i)
        scanf("%d", &Rope[i]);

    double l = 0, r = 1e9;
    int i = 100;
    while(i--)
    {
        double mid = (l + r) / 2;
        if(check(mid)) l = mid;
        else r = mid;
    }

    printf("%.2f\n", l);

    return 0;
}


活动打卡代码 AcWing 1227. 分巧克力

hairrrrr
5小时前
#include<cstdio>

#define N 100010

typedef long long LL;

int n, k;
int H[N], W[N];


bool check(int mid)
{
    LL cnt = 0;
    for(int i = 0; i < n; ++i)
    {
        cnt += (LL)(H[i] / mid) * (W[i] / mid);
        if(cnt >= k) return true;
    }
    return false;
}

int main(void)
{
    scanf("%d%d", &n, &k);

    for(int i = 0; i < n; ++i)
    {
        scanf("%d%d", &H[i], &W[i]);
    }

    int l = 1, r = (int)1e5;
    while(l < r)
    {
        // 向下取整
        int mid = l + r + 1>> 1;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }
    printf("%d\n", l);
    return 0;
}



#include<cstdio>
#include<iostream>
#pragma GCC optimize(3)

using namespace std;

int a[50];

int f(int n)
{
    if(n == 0 || a[n]) return a[n];
    a[n] = f(n - 1) + f(n - 2);
    return a[n];
}

int main(void)
{
    a[1] = 1;
    int n;
    scanf("%d", &n);
    printf("%d\n", f(n));;

    return 0;
}



有没有大佬帮忙看一下为什么会 段错误啊

#define _CRT_SECURE_NO_WARNINGS

#include<cstdio>
#include<iostream>

using namespace std;


#define MOD (int)10000 
#define N 2


struct mat
{
    int a[N][N];

    mat()
    {
        for (int i = 0; i < N; ++i)
        {
            for (int j = 0; j < N; ++j)
            {
                a[i][j] = 0;
            }
        }
    }

    void setUnitMat()
    {
        for (int i = 0; i < N; ++i)
            a[i][i] = 1;
    }
};

mat&& matMul(mat& a, mat& b)
{
    mat res;
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            for (int k = 0; k < N; ++k)
            {
                res.a[i][j] += (a.a[i][k]  * b.a[k][j]) % MOD;
                res.a[i][j] % MOD;
            }
        }
    }
    return std::move(res);
}

mat&& fastPow(mat q, int n)
{
    mat u;
    u.setUnitMat();
    while (n > 0)
    {
        if (n & 1) u = matMul(u, q);
        q = matMul(q, q);
        n >>= 1;
    }
    return std::move(u);
}

int main(void)
{
    int n;
    mat q;
    q.a[0][0] = q.a[0][1] = q.a[1][0] = 1;
    q.a[1][1] = 0;

    scanf("%d", &n);
    while (n != -1)
    {
        if (n <= 1)
        {
            printf("%d\n", n);
            scanf("%d", &n);
            continue;
        }
        mat res = fastPow(q, n - 1);
        printf("%d\n", res.a[0][0] % MOD);
        scanf("%d", &n);
    }

    return 0;
}